title: Draw on Panel, save as Bitmap
body: <p>I'm trying to make a simple application where the user can draw on the Panel and save it to their computer as a bitmap. When I proceed to the save part, however, all I get is an empty (white) bitmap.</p>
  
  <p>I've been browsing many other solutions and I am pretty sure I am saving the bitmap the correct way, so I am starting to wonder if my drawing process is incorrect. What exactly is wrong here?</p>
  
  <pre><code>public partial class Form1 : Form
  {
  
      SolidBrush brush;
      Pen pen;
      Point[] points = new Point[3];
      Graphics display;
      Bitmap bmap;
  
      public Form1()
      {
          InitializeComponent();
          display = panel1.CreateGraphics();
          bmap = new Bitmap(panel1.Width, panel1.Height);
      }
  
  
      private void panel1_MouseDown(object sender, MouseEventArgs e)
      {
          brush = new SolidBrush(Color.Black);
          pen = new Pen(Color.Black);
  
  
          display.FillEllipse(brush, e.X, e.Y, 10, 10);
          panel1.DrawToBitmap(bmap, new Rectangle(0, 0, panel1.Width, panel1.Height));
  
          //this.Invalidate();
      }
  
  
  
      private void clearToolStripMenuItem_Click(object sender, EventArgs e)
      {
          Graphics display = panel1.CreateGraphics();
          display.Clear(panel1.BackColor);
  
      }
  
      private void saveToolStripMenuItem_Click(object sender, EventArgs e)
      {
  
  
  
          bmap.Save(@"C:\Temp\Test.bmp");
  
      }
  }
  </code></pre>
  
  <p>EDIT
  With this revision, I just get a black bmp and I don't even see elipses being created anymore on my screen. Although I did notice that if I put invalidate and Draw to bitmap back in the mousedown event, then the save button will save the last ellipse, while there is still nothing appearing on my screen.</p>
  
  <pre><code>private void panel1_MouseDown(object sender, MouseEventArgs e)
          {
  
              mousedown = true;
              x = e.X;
              y = e.Y;
  
          }
  
          private void panel1_Paint(object sender, PaintEventArgs e)
          {
              //Graphics g = e.Graphics;
              if(mousedown==true)
  
              {
              brush = new SolidBrush(Color.Black);
              pen = new Pen(Color.Black);
  
              Graphics.FromImage(bmap).FillEllipse(brush, x, y, 10, 10);
              panel1.Invalidate();
             //panel1.DrawToBitmap(bmap, new Rectangle(0, 0, panel1.Width, panel1.Height));
  
  
              //panel1.Invalidate();
  
              }
          }
  </code></pre>