C#如何截取当前程序窗口的截图

2025-05-01 03:42:47
推荐回答(1个)
回答1:

Bitmap bit = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bit);
g.CopyFromScreen(new Point(this.Location.X,this.Location.Y), new Point(0, 0), bit.Size);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "bmp|*.bmp|jpg|*.jpg|gif|*.gif";
if (saveFileDialog.ShowDialog() != DialogResult.Cancel)
{
bit.Save(saveFileDialog.FileName);
}
g.Dispose();
}