用c#捕获Windows窗体的屏幕截图 [英] Capture Screenshot Windows Forms by c#

查看:226
本文介绍了用c#捕获Windows窗体的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目(应用程序)中有某种表单,而在主表单中有一个按钮(Capture Button)当我单击捕获按钮时,我的程序将捕获所有其他表单的屏幕截图

I have some form in one project (application) and in the main form have one button (Capture Button) when I click in capture button my program capture Screenshot all another forms

其他形式可能会最小化或尚未显示!或后面的主要表单

other forms maybe minimize or not show yet ! or behind Main forms

我使用此代码

Form1 theForm = new Form1();                           
using (var bitmap = new Bitmap(theForm.Width, theForm.Height))
{
       theForm.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height));
       bitmap.Save(@"c:\TEST.bmp");
}

它工作正常,但在捕获的图像中不显示Forms Control

it work fine but don't show Forms Control in the captured image

当表单未显示或最小化或在另一表单后面时,如何捕获某些表单?

How can i captured some forms when forms not showed or minimize or behind another form ?

谢谢

推荐答案

尝试一下

 Rectangle bounds = Screen.GetBounds(Point.Empty);
 using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
 {
    using (Graphics g = Graphics.FromImage(bitmap))
    {
       g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }
    bitmap.Save("c://My_Img.jpg", ImageFormat.Jpeg);
 }

这篇关于用c#捕获Windows窗体的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆