如果我有一个绘制矩形,圆形和直线的程序,并且我想使用SaveFileDialog保存用户在表单上绘制的图片,那该怎么办呢?
我知道如何使用SaveFileDialog保存文本文件,只是不确定如何保存表单。
答案 0 :(得分: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);
}
}
}
答案 1 :(得分:1)
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 );
}