PictureBox at programme launch



  • When the program is launched at PictureBox, the coordinate axis shall be painted. Designer Form1 wrote the following code:

            Graphics g = pictureBox1.CreateGraphics();
            g.Clear(Color.White);
            g.DrawLine(new Pen(Color.Black, 4), pictureBox1.Width / 2, 0, pictureBox1.Width / 2, pictureBox1.Height);
            g.DrawLine(new Pen(Color.Black, 4), 0, pictureBox1.Height / 2, pictureBox1.Width, pictureBox1.Height / 2);
    

    But there's nothing going on in the launch... I tried to put the same code in the shape event. Loadeffects 0. What am I doing wrong?



  • Precisely create a batmap in a picchurbox and address it.

      pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
      using (Graphics g = Graphics.FromImage(pictureBox1.Image))
      {
        g.Clear(Color.White);
        g.DrawLine(new Pen(Color.Black, 4), pictureBox1.Width / 2, 0, pictureBox1.Width / 2, pictureBox1.Height);
        g.DrawLine(new Pen(Color.Black, 4), 0, pictureBox1.Height / 2, pictureBox1.Width, pictureBox1.Height / 2);
      }
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2