gpt4 book ai didi

C# 打印屏幕事件窗口

转载 作者:行者123 更新时间:2023-11-30 21:16:13 30 4
gpt4 key购买 nike

我目前正在尝试使用 Visual C# 在屏幕上打印事件窗口。我有这段代码:

SaveFileDialog saveImageDialog = new SaveFileDialog();
saveImageDialog.Title = "Select output file:";
saveImageDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
//saveImageDialog.FileName = printFileName;
if (saveImageDialog.ShowDialog() == DialogResult.OK)
{
// Set the bitmap object to the size of the screen
bmpScreenshot = new Bitmap(this.Bounds.Width, this.Bounds.Height, PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(this.Bounds.X, this.Bounds.Y, 0, 0, this.Bounds.Size, CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen
bmpScreenshot.Save(saveImageDialog.FileName, ImageFormat.Png);
}

但这段代码也捕获了 SaveImageDialog。有办法解决这个问题吗?非常感谢。

最佳答案

最简单的方法是切换代码:

// Set the bitmap object to the size of the screen
bmpScreenshot = new Bitmap(this.Bounds.Width, this.Bounds.Height,
PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(this.Bounds.X, this.Bounds.Y, 0, 0,
this.Bounds.Size, CopyPixelOperation.SourceCopy);

SaveFileDialog saveImageDialog = new SaveFileDialog();
saveImageDialog.Title = "Select output file:";
saveImageDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
//saveImageDialog.FileName = printFileName;
if (saveImageDialog.ShowDialog() == DialogResult.OK)
{
// Save the screenshot to the specified path that the user has chosen
bmpScreenshot.Save(saveImageDialog.FileName, ImageFormat.Png);
}

首先创建屏幕截图,然后显示保存对话框并将其保存到光盘(如果对话框通过确定关闭)。

问题是,在您的代码中,程序没有时间重新绘制您的表单。如果您想保留代码的结构,您需要给它一些时间来处理未决事件,可能通过调用 Application.DoEvents 来实现。 .

关于C# 打印屏幕事件窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5336553/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com