C#中 窗体带有滚动条 如何将此窗体的所有内容都打下来
CaptureScreen应该不太管用 哪位大哥有好点的办法,将当前窗体打印出来但是窗体是带有滚动条的,显示不开 --------------------编程问答-------------------- 转换成图片,再打印图片。
--------------------编程问答-------------------- 是要打印窗体吗,这样:
调用BitBlt API将整个Form画到一个Image上,然后再将这个Image打印出来。基本步骤如下:
1. Import the BitBlt API function
2. Capture the image of the form
3. Draw the image in the PrintPage event
具体代码如下例所示:
[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private const Int32 SRCCOPY = 0xCC0020;
private Bitmap memImage;
private void PrepareImage()
{
Graphics graphic = this.CreateGraphics();
Size s = this.Size;
memImage = new Bitmap(s.Width, s.Height, graphic);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = graphic.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height,dc1, 0, 0, SRCCOPY);
graphic.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
}
private void button1_Click(object sender, System.EventArgs e)
{
PrepareImage();
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memImage,0,0);
} --------------------编程问答-------------------- To:jcyluck
我先在用的就是你的这段截屏代码,但是当窗口出现滚动条也就是屏幕显示不开时打印不了全部的窗体内容 --------------------编程问答-------------------- 不能直接获得
具体思路如下:
1、先截屏,然后保存;
2、如果存在滚动条,发送pagedown消息,重复1;否则结束。 --------------------编程问答-------------------- 这个例子比较类似,你可以进行参考
Image Capture Whole Web Page using C#
http://www.codeproject.com/cs/media/IECapture.asp --------------------编程问答-------------------- 我觉得这种方法不好 第一是万一有别的窗体挡着显示不全,截取的时候就不全了,第二打出来效果非常不清晰
补充:.NET技术 , C#