我正在尝试使用下面的代码保存打印屏幕,但它不起作用
private void button3_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
button1.Visible = false;
button2.Visible = false;
Bitmap bitmap = new Bitmap(this.Width, this.Height);
this.DrawToBitmap(bitmap, this.ClientRectangle);
bitmap.Save("myPrintScreen.bmp");
button1.Visible = true;
button2.Visible = true;
}
}
答案 0 :(得分:2)
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
// Save file, use saveFileDialog1.FileName
}
您可以使用Filename
Property设置文件名。以你的例子:
saveFileDialog1.FileName = "myPrintScreen.bmp";
[问题编辑后编辑] 更改
this.DrawToBitmap(bitmap, this.ClientRectangle);
到:
using(var Stream = saveFileDialog1.OpenFile())
{
bitmap.Save(Stream , ImageFormat.Bmp);
}
答案 1 :(得分:1)
您需要SaveFileDialog。 看一下那里提供的例子。