保存位图/“屏幕截图”当表单未显示时,表单无法工作
我正在开发一个具有多个表单的 Windows 表单应用程序。我想将其中一份表格打印为图像文件。
我正在使用这个示例:单击
我有一个带有各种标签、文本框和按钮的表单。当我按下按钮运行 SaveAsBitmap
时,表单及其元素会正确保存为 bmp 文件(就像您截取了它的屏幕截图并保存为图像一样)。
现在,我有另一个不向用户显示的表单。 (这是一个没有表单边框样式的表单。) 我想在这个表单上而不是另一个表单上保存 bmp。但无论我将 SaveAsBitmap 方法放在该表单的代码中的哪个位置,它都只保存表单的背景(没有标签等项目)。 但是,如果我将 this.ShowDialog()
放在某个地方来显示表单,然后运行 SaveAsBitmap
方法,它就会按预期工作。
所以这里的要点是,当表单未显示时它无法正常工作。
当使用 SaveAsBitmap
方法时,我写: SaveAsBitmap(this , "C:\\test.bmp");
感谢任何帮助!
I am developing a windows forms application with multiple forms. I would like to print one of the forms as an image file.
I am using this example: click
I have a form with various labels, textboxes, and a button. When I run SaveAsBitmap
by pressing the button, the form and its elements is correctly saved as a bmp file (just as if you took a screenshot of it and saved as an image).
Now, I have another form which is not to be shown to the user. (It's a form with no form border style.)
I would like to do the bmp saving on this form instead of the other. But no matter where in the code of this form I put the SaveAsBitmap
method, it only saves the background of the form (no items such as labels).
However, if I put this.ShowDialog()
somewhere to show the form, and then afterwards run the SaveAsBitmap
method, it works as it should.
So the main point here is the fact that it does not work correctly when the form is not shown.
When using the SaveAsBitmap
method, I write: SaveAsBitmap(this, "C:\\test.bmp");
Any help appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用;
This works for me;