.net - 将Windows窗体转换为图片

原文 标签 .net winforms drawing

Convert windows form to a picture

I looked around and I may have confused google with the keywords.

I am looking to implement a support module in my windows forms application where when a user clicks on a button, an email is sent to the support team, with an attachment of a screenshot (form in question)

I am looking for something like

form.SaveAsImage(path)

any thoughts on how this can be implemented or have I missed the obvious

.net 3.5

Answer

Try using the Control.DrawToBitmap method and make sure the form has focus when you run the code.

using (Graphics gfx = form.CreateGraphics())
{
    using (Bitmap bmp = new Bitmap(form.Width, form.Height, gfx))
    {
        form.DrawToBitmap(bmp, new Rectangle(0, 0, form.Width, form.Height));
        bmp.Save(fileName);
    }
}

翻译

我环顾四周,可能使Google与关键字混淆了。

我希望在Windows窗体应用程序中实现一个支持模块,在该模块中,当用户单击按钮时,会将一封电子邮件发送给支持团队,并附带屏幕截图(有问题的窗体)

我正在寻找类似的东西

form.SaveAsImage(路径)

关于如何实施的任何想法,或者我错过了显而易见的

.net 3.5
最佳答案
尝试使用Control.DrawToBitmap方法,并在运行代码时确保表单具有焦点。

using (Graphics gfx = form.CreateGraphics())
{
    using (Bitmap bmp = new Bitmap(form.Width, form.Height, gfx))
    {
        form.DrawToBitmap(bmp, new Rectangle(0, 0, form.Width, form.Height));
        bmp.Save(fileName);
    }
}
相关推荐

.net - 正则表达式匹配单词

c# - 获取今天之后第n个星期日的DateTime

c# - C#:在漫长的过程中修复白屏

c# - 为什么以及如何在旧版应用程序代码中实施初始单元测试

.net - 更新EF模型:缺少表格

c# - 如果元素来自ItemSsource,如何在WPF TreeView中聚焦元素?

c# - 如何通过提供节点ID读取xml中的节点值

.net - 为什么在.Net中使用“ new EventHandler(Handler)”?

c# - 我如何显示生成版本以及它在程序中以64位还是32位运行?

c# - 在数组中搜索特定字段中的指定值