2012-03-28 96 views
-1

我有一个用Visual Studio(C#)编写的有趣应用程序,我想知道 - 我所做的是我在窗体上以某种方式绘制面板 - 如果可以渲染窗体而不用截图?Visual C# - 从窗体渲染图像?

感谢

回答

3

如果“采取截图”你的意思是“送PrtSc键”,然后有一个更好的办法,用System.Drawing.Graphics.CopyFromScreen

using(Bitmap b = new Bitmap(this.ClientSize.Width, this.ClientSize.Height)) { 
    using(Graphics g = Graphics.FromImage(b)) { 
     g.CopyFromScreen(this.PointToClient(Point.Empty), Point.Empty, this.ClientSize); 
    } 

    // Your form is now rendered into b. 
} 

如果要包括边界,只需使用Size代替ClientSizethis.Location而不是this.PointToClient(Point.Empty)

或者,你可以使用this.DrawToBitmap

using(Bitmap b = new Bitmap(this.Width, this.Height)) { 
    this.DrawToBitmap(b, new Rectangle(0, 0, this.Width, this.Height)); 

    // Your form is now rendered into b. 
} 

这会工作,即使你的形式不具有焦点。但是,如果Aero处于活动状态,它将绘制边框并以Windows Basic样式绘制。

-1

不,这是不可能捕捉到视觉的形式作为比是通过某种screenshotting库(如果这就是你在问什么)的提供的其他图像。