-2

我正在尝试使用下面的代码保存打印屏幕,但它不起作用

 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;
        }

    }
4

2 回答 2

2

使用SaveFileDialog

 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);
}
于 2013-01-14T12:19:17.630 回答
1

您需要SaveFileDialog。看看那里提供的示例。

于 2013-01-14T12:19:32.093 回答