如何使用SaveFileDialog保存表单

Big*_*Bug 0 c# drawing savefiledialog

如果我有一个绘制矩形,圆形和线条的程序,我想使用SaveFileDialog保存用户在表单上绘制的图片,这将如何完成?

我知道如何使用SaveFileDialog保存文本文件,只是不知道如何保存表单.

Eni*_*ate 5

你可以尝试这个....

它将使用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);
        }
     }
  }
Run Code Online (Sandbox Code Playgroud)