如何在C#中没有SavefileDialog的同一文件夹中保存severel图像(.png,.jpg)文件

时间:2015-02-10 03:06:27

标签: c#

我正在用C#创建一个快照应用程序,我想让它在没有SaveFileDilog的情况下保存快照。我使用了一个计时器。 意味着当计时器停止时将没有提示保存文件,它将在后台执行。 并提前感谢:) 代码是

private void timer1_Tick(object sender, EventArgs e)
    {
        Graphics GH = Graphics.FromImage(Form1.bm as Image);
        GH.CopyFromScreen(0, 0, 0, 0, Form1.bm.Size);
        this.pic_box.SizeMode = PictureBoxSizeMode.StretchImage;
        pic_box.Image = Form1.bm;
        timer1.Enabled = false;
        SaveFileDialog SFD = new SaveFileDialog();
        SFD.Filter = "Image File | *.PNG";
        SFD.DefaultExt = ".png";
        SFD.FileName = "cap(#).png";
        if (SFD.ShowDialog() == DialogResult.OK)
        {
            Form1.bm.Save(SFD.FileName);
            MessageBox.Show("Saved", "Saved successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }

1 个答案:

答案 0 :(得分:0)

然后删除SaveFileDialog:

private void timer1_Tick(object sender, EventArgs e)
{
    Graphics GH = Graphics.FromImage(Form1.bm as Image);
    GH.CopyFromScreen(0, 0, 0, 0, Form1.bm.Size);
    this.pic_box.SizeMode = PictureBoxSizeMode.StretchImage;
    pic_box.Image = Form1.bm;
    timer1.Enabled = false;
    Form1.bm.Save("cap(#).png");
    this.Close();
}