Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual C#-从窗体渲染图像?_C#_Visual Studio - Fatal编程技术网

Visual C#-从窗体渲染图像?

Visual C#-从窗体渲染图像?,c#,visual-studio,C#,Visual Studio,我有一个用Visual Studio(C#)编写的有趣的应用程序,我想知道——我要做的是以某种方式在表单上绘制面板——是否可以在不截图的情况下渲染表单 谢谢不,除了某种截屏库提供的图像之外,不可能将表单的视觉效果捕获为图像(如果您是这样要求的)。如果“截屏”是指“发送PrtSc”,那么有一种更好的方法,使用: 如果要包含边框,只需使用Size而不是ClientSize,以及this.Location而不是this.PointToClient(Point.Empty) 或者,您可以使用this.D

我有一个用Visual Studio(C#)编写的有趣的应用程序,我想知道——我要做的是以某种方式在表单上绘制面板——是否可以在不截图的情况下渲染表单


谢谢

不,除了某种截屏库提供的图像之外,不可能将表单的视觉效果捕获为图像(如果您是这样要求的)。

如果“截屏”是指“发送PrtSc”,那么有一种更好的方法,使用:

如果要包含边框,只需使用
Size
而不是
ClientSize
,以及
this.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基本样式绘制边框

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.
}