0

I'd like to draw X and Y axes on a panel at application launch. I've created this method:

    public void Draw_axes()  
    {
    Graphics gs = panel_main.CreateGraphics();
    gs.DrawLine(pen, panel_main.Width / 2, 0, panel_main.Width / 2,     (panel_main.Height ));  //Asse Y
         gs.DrawLine(pen, 0, panel_main.Height /2, panel_main.Width, panel_main.Height / 2);  // Asse X
     } 

I tried to insert it in a Load but it doesn't work. I tried with the timer (I don't know how to use it very well though) but it doesn't work.

Could you please help me?

cristakey IT
  • 53
  • 1
  • 9
  • 1
    What do you mean you tried it in a `Load`? – Mark C. Feb 01 '17 at 17:30
  • Drawing anything on the form is going to get wiped out every time the form is repainted (which happens a lot). you need to put this in the paint event. – DavidG Feb 01 '17 at 17:33
  • What's the exact code I shoud write? I'm very new in C# programming. Thanks – cristakey IT Feb 01 '17 at 17:42
  • Calling `CreateGraphics` like that will not work properly. As soon as the PictureBox is repainted, you will lose what you drew. Instead, handle the `Paint` event of the `PictureBox` and draw you axes there and anything else that needs drawing. – Chris Dunaway Feb 01 '17 at 19:05
  • Thanks, I finally managed to draw the axes correctly – cristakey IT Feb 01 '17 at 19:28

0 Answers0