0
votes

If i have a program which draws rectangles, circles and lines and i want to save the picture which the user has drawn on the form using SaveFileDialog, how would this be done?

I know how to save a text file using SaveFileDialog, just not sure how to save the form.

2
Do you know how to capture the Image drawn? - Shamim Hafiz - MSFT

2 Answers

5
votes

you can try this....

It will save form content as bitmap with SaveFileDialog

  public class Form1
  {

      private Bitmap objDrawingSurface;        
      private Rectangle rectBounds1;

      private void Button1_Click(object sender, System.EventArgs e) 
      {
         objDrawingSurface = new Bitmap(this.Width, this.Height, Imaging.PixelFormat.Format24bppRgb);
         rectBounds1 = new Rectangle(0, 0, this.Width, this.Height);
         this.DrawToBitmap(objDrawingSurface, rectBounds1);
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.Filter = "JPG Files (*.JPG) |*.JPG";
        if ((sfd.ShowDialog == Windows.Forms.DialogResult.OK))
        {
            objDrawingSurface.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
     }
  }
1
votes
public void SaveFormToFile(string fileName)
{
    System.Drawing.Bitmap b = new Bitmap(this.Bounds.Width, this.Bounds.Height);
    this.DrawToBitmap(b, this.Bounds);
    b.Save(fileName );
}