【问题标题】:Is there a way to make a screenshot of a component in C# [closed]有没有办法在 C# 中制作组件的屏幕截图 [关闭]
【发布时间】:2015-01-09 10:44:31
【问题描述】:

有没有办法在 C# 中制作组件的屏幕截图

我有一个带有图形的面板,我想制作这个面板的屏幕截图并在图片框中显示这个屏幕截图。

非常感谢您的支持。

【问题讨论】:

  • Windows 窗体还是 WPF?
  • 您可能需要检查 Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
  • 确保图形是在 Paint 事件中创建或触发的!然后答案将起作用。如果没有,请更正您的代码以正确执行!

标签: c# winforms panel picturebox


【解决方案1】:

如果您使用的是 windows 窗体,请尝试使用 Control.DrawToBitmap 方法并确保在您运行代码时窗体具有焦点。

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

您可以使用panel picturebox 或其他从Control 继承的控件而不是form

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-04
    • 2022-10-14
    • 2018-12-23
    • 2019-05-27
    • 1970-01-01
    相关资源
    最近更新 更多