title: How to save drawn shapes as images c#
body: <p>I am creating a painting program, I have figured out how to draw shapes to the Form, but how do I save them, I tried to do this:  </p>
  
  <pre><code>Image bmp = new Bitmap(this.Width - panel1.Width, this.Height - panel1.Height);
  using (Graphics g = Graphics.FromImage(bmp))
  {
  
  }
  bmp.Save("test.bmp"); 
  </code></pre>
  
  <p>It saves test.bmp but the file is empty? </p>
  
  <p>Heres is my entire code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  namespace Paint_Program
  {
  
  public partial class PaintImg : Form
  {
  
  
  
      public Boolean veryimportantbool = false;
      int drawcount = 0;
      int brushsize = 16;
  
      public PaintImg()
      {
          InitializeComponent();
          //Cursor drawCursor = new Cursor("Pencil.cur");
          //this.Cursor = drawCursor;
  
  
      }
  
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
  
          //Cursor.Position = new Point(this.Location.X - this.Width / 2, this.Location.Y - this.Height / 2)
          UserControl1 userc1 = new UserControl1();
          userc1.Show();
          brushsize = Convert.ToInt16(label1.Text);
  
  
      }
  
      private void rectangleShape1_Click(object sender, EventArgs e)
      {
  
      }
  
      private void Test_Click(object sender, EventArgs e)
      {
          //testing 
          //Console.WriteLine("X:" + mousex);
          //onsole.WriteLine("Y: " + mousey);
      }
  
      private void Form1_SizeChanged(object sender, EventArgs e)
      {
  
      }
  
  
      public void Form1_MouseClick(object sender, MouseEventArgs i)
      {
  
              drawcount = drawcount + 1;
              System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
              System.Drawing.Graphics formGraphics;
              formGraphics = this.CreateGraphics();
              formGraphics.FillRectangle(myBrush, new Rectangle(i.X, i.Y, brushsize, brushsize));
              myBrush.Dispose();
              formGraphics.Dispose();
              count.Text = Convert.ToString(drawcount);
  
  
      }
  
      private void newToolStripButton_Click(object sender, EventArgs e)
      {
          //SetupDoc newsetup = new SetupDoc();
          //newsetup.ShowDialog();
      }
  
      private void PaintImg_MouseMove(object sender, MouseEventArgs e)
      {
  
      }
  
      private void panel1_Paint(object sender, PaintEventArgs e)
      {
  
      }
  
      private void panel1_Click(object sender, MouseEventArgs e)
      {
          drawcount = drawcount + 1;
          System.Drawing.SolidBrush myBrush = new      System.Drawing.SolidBrush(System.Drawing.Color.Red);
          System.Drawing.Graphics formGraphics;
          formGraphics = this.CreateGraphics();
          formGraphics.FillRectangle(myBrush, new Rectangle(e.X, e.Y, brushsize, brushsize));
          myBrush.Dispose();
          formGraphics.Dispose();
          count.Text = Convert.ToString(drawcount);
      }
  
      private void label1_Click(object sender, EventArgs e)
      {
  
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          brushsize = brushsize + 1;
          label1.Text = Convert.ToString(brushsize);
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          brushsize = brushsize - 1;
          label1.Text = Convert.ToString(brushsize);
      }
  
      private void button3_Click(object sender, EventArgs e)
      {
          Image bmp = new Bitmap(this.Width - panel1.Width, this.Height - panel1.Height);
          using (Graphics g = Graphics.FromImage(bmp))
          {
  
          }
          bmp.Save("test.bmp");
      }
  
  }
  }
  </code></pre>
  
  <p>I would appreicate it if anyone new how to do this???? :D</p>