0

I want to draw a line in c# and it is not working. What is wrong with my code?

private void GraficProfit_Load(object sender, EventArgs e)
{
    Bitmap b = new Bitmap(1000,1000);
    pictureBox1.Image = b;
    Graphics g = pictureBox1.CreateGraphics();
    g.DrawLine(new Pen(Color.Red, 10), 10, 10, 100, 190);
}
David Refoua
  • 3,476
  • 3
  • 31
  • 55
Mihai
  • 17
  • 5
  • 1
    __Either__ replace : `Graphics g = pictureBox1.CreateGraphics();` with `Graphics g = Graphics.FromImage(b)` also moving the assignment after the drawing __or__ put this `e.Graphics.DrawLine(new Pen(Color.Red, 10), 10, 10, 100, 190);` into the `Paint` event of the PictureBox. The former draws into the Bitmap, the latter onto the Control. See [here for mor](http://stackoverflow.com/questions/27337825/picturebox-paintevent-with-other-method/27341797?s=5|0.3441#27341797) on the difference! – TaW Apr 03 '17 at 17:19
  • Your second choice is my vote. – Trey Apr 03 '17 at 17:23

0 Answers0