是要打印窗体吗,这样:
调用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);
}
调用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);
}
解决方案 »
- 在线等待C#修改注册表 把指点占地加入信任,信任站点安全级别最低,下载未签名的Activex控件设置为启用状态
- winform智能开发,没有WebClient怎么办?
- 在打印Infragistics NetAdvantage的wingrid时怎样设置打印标题?
- 在VS.NET2008开发环境中有没有类似SQL SERVER2000的企业管理器功能,比如能附加数据库、创建数据库等。
- 怎样把WinForm中的控件与数据库绑定
- C#.NET检查用户名是否存在并返回结果给变量
- treeview绑定数据库中数据库名 表名
- 怎樣在DATAGRID的欄中加入指定的控件,如某一欄加入combobox控件到DATAGRID中.
- 急急急!!后台数据库取值,然后调用js添加行,并且给添加的行赋值,怎么实现啊。(可加分)
- 如何把一个string转换成int
- winform的listview和imagelist 比较急,在线等
- WFP TabItem设置trigger无效
我先在用的就是你的这段截屏代码,但是当窗口出现滚动条也就是屏幕显示不开时打印不了全部的窗体内容
1、先截屏,然后保存;
2、如果存在滚动条,发送pagedown消息,重复1;否则结束。
Image Capture Whole Web Page using C#
http://www.codeproject.com/cs/media/IECapture.asp