Panel does not become invisible if Chart’s Paint event is activated

Asked

Viewed 60 times

0

Good night,

Staff would like a help, so with a doubt, well I am developing an application, in which the user chooses 5 dates of any working days of the month,e gera um gráfico diferenciado com a cotação de cada dia, certo, esse grafico diferenciado (Triangulos e linhas) is made from the Paint Event, which has an if that only expects a true value for a bool to make the shapes, when the user chooses the dates and clicks on the "Generate" button was for the date options panel to be Visible=false, however when set the value of the bool variable for the Paint event as true, and the Paint starts to rotate, this panel does not add up by staying on the screen, already tried to put the Visible line inside the if of the Paint did not help either. If anyone knows why this is happening, and show me how to pack

Print: http://imgur.com/D798Xeo

private void btGerarGraficos_Click(object sender, EventArgs e)
        {
            listaPETR3 = acessar.carregarPregoes(cbData1.Text, cbData2.Text, cbData3.Text, cbData4.Text, cbData5.Text, "PETR3");
            listaPETR4 = acessar.carregarPregoes(cbData1.Text, cbData2.Text, cbData3.Text, cbData4.Text, cbData5.Text, "PETR4");

            GerarGraficosCandles();

            CriarPontosTriangulos();

            pnlConfigurarDatas.Visible = false;

            if (checkPETR3.Checked)
            {
                drawPETR3Banco = true;
            }

            if (checkPETR4.Checked)
            {
                drawPETR4Banco = true;
            }
        }

    private void chartPETR4_Paint_Banco(object sender, PaintEventArgs e)
    {
        if (drawPETR4Banco)
        {
            double posiX, open, close, max, min;

            for (int i = 0; i < 5; i++)
            {
                i++;
                posiX = chartPETR4.ChartAreas["areaTriangulo4"].AxisX.ValueToPixelPosition(i);
                i--;
                open = chartPETR4.ChartAreas["areaTriangulo4"].AxisY.ValueToPixelPosition(listaPETR4[i].Abertura);
                close = chartPETR4.ChartAreas["areaTriangulo4"].AxisY.ValueToPixelPosition(listaPETR4[i].Fechamento);
                max = chartPETR4.ChartAreas["areaTriangulo4"].AxisY.ValueToPixelPosition(listaPETR4[i].Maximo);
                min = chartPETR4.ChartAreas["areaTriangulo4"].AxisY.ValueToPixelPosition(listaPETR4[i].Minimo);

                if (listaPETR4[i].Abertura < listaPETR4[i].Fechamento)
                {
                    Point[] posicoes = {
                                           new Point(Convert.ToInt32(posiX) - 20, Convert.ToInt32(open)),
                                           new Point(Convert.ToInt32(posiX) + 20, Convert.ToInt32(open)),
                                           new Point(Convert.ToInt32(posiX) + 20, Convert.ToInt32(close))
                                       };
                    e.Graphics.DrawLine(p, Convert.ToInt32(posiX), Convert.ToInt32(min), Convert.ToInt32(posiX), Convert.ToInt32(max));
                    e.Graphics.FillPolygon(bVerde, posicoes);
                }

                else if (listaPETR4[i].Abertura > listaPETR4[i].Fechamento)
                {
                    Point[] posicoes = {
                                           new Point(Convert.ToInt32(posiX) + 20, Convert.ToInt32(close)),
                                           new Point(Convert.ToInt32(posiX) - 20, Convert.ToInt32(open)),
                                           new Point(Convert.ToInt32(posiX) - 20, Convert.ToInt32(close))
                                       };
                    e.Graphics.DrawLine(p, Convert.ToInt32(posiX), Convert.ToInt32(min), Convert.ToInt32(posiX), Convert.ToInt32(max));
                    e.Graphics.FillPolygon(bVermelho, posicoes);
                }
            }
            chartPETR4.Invalidate(true);
        } 
    }
  • Young man, put the code.

  • It’s kind of long I’ll put the event code click button and the event Paint of Chart in real are two Charts but to get ready in one just change in the other that is similar

1 answer

1


After changing the variable to true or false, you should paint Chart again.

The code would look like this: pnlConfigurarDatas.Visible = false;

if (checkPETR3.Checked) { drawPETR3Banco = true; }

if (checkPETR4.Checked) { drawPETR4Banco = true; } chartPETR4.Refresh(); chartPETR3.Refresh();

I would also take those if’s. Final code:

pnlConfigurarDates.Visible = false;

drawPETR3Banco = checkPETR3.Checked; drawPETR4Banco = checkPETR4.Checked;

chartPETR4.Refresh(); chartPETR3.Refresh();

  • Thanks friend :), po it’s really stupid my use the if’s Sauushsuhuasush but thanks there

Browser other questions tagged

You are not signed in. Login or sign up in order to post.