When starting the program, the coordinate axes should be drawn in the PictureBox. In the Form1 constructor, I 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 at startup nothing happens ... I tried to cram the same code into an event of the form Load , effect 0. What am I doing wrong?

    1 answer 1

    Pre-create a bitmap in pcchurbbox and access 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); } 
    • Happened! Thank! - user215568