S
S
Sergey Khlopov2019-08-26 21:23:00
C++ / C#
Sergey Khlopov, 2019-08-26 21:23:00

Why is the graph not drawn on the Load event in from?

Hello, please tell me, I use GDI + in order to draw a graph, the laboratory work is like this. And for some reason this code does not display the chart after the Form1_Load event, but if you add a button to the form and call the same code on the click event, it works:

private void Form1_Load(object sender, EventArgs e)
        {
            int[,] arrayPoint = {
                { 140, 120, 180, 140 },
                { 70, 100, 60, 40 },
            };
            Graphics g = Graphics.FromHwnd(panel1.Handle);

            Graph objGraph = new Graph();
            objGraph.Rows = arrayPoint;

            objGraph.SetCenterCoodrinate(g, panel1);
            objGraph.DrawAxis();
            objGraph.DrawLabel();
            objGraph.DrawPolygon();
        }

The Graph class is my class that draws a graph. Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Khlopov, 2019-08-28
@Shlop

The diagram began to be drawn when I placed my code in the Paint event of the form, although perhaps there is a better solution, please tell me if you have any ideas, and by the way, if you do alt + tab with this solution, then the diagram disappears and then you need to point, for example, at some button on the form so that it appears again, I don’t understand a little why this is happening

private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = Graphics.FromHwnd(panel1.Handle);

            Graph objGraph = new Graph();
            objGraph.Rows = arrayPoint;
            objGraph.SetCenterCoodrinate(g, panel1);
            objGraph.ClearAll();
            objGraph.DrawAxis();
            objGraph.DrawLabel();
            objGraph.DrawPolygon();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question