C#中如何对当前窗体进行打印预览
2008-05-01 02:31
471 查看
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
CaptureScreen();
printPreviewDialog1.Show();
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
CaptureScreen();
printPreviewDialog1.Show();
相关文章推荐
- C#中如何对当前窗体进行打印预览
- 如何对窗体进行打印预览 (Visual C#)
- ACCESS如何打印窗体中当前显示的记录
- .Net - C# 如何判断程序里某个窗体是否为Windows的当前活动窗体?(附代码)
- C# 如何在窗体项目的类中获得当前窗体的对象
- ABAP 如何判断调用smartforms时是进行打印还是预览
- 用flex如何制作不规则的表格,进行打印预览。而且可以打印。譬如制作如下表单:
- C#如何获取当前项目的目录,并以当前为根进行修改
- 利用 .NET Printing 命名空间从 Windows 窗体应用程序中进行预览和打印
- C# 如何通过委托进行窗体1到窗体2的传值
- 利用 .NET Printing 命名空间从 Windows 窗体应用程序中进行预览和打印
- 如何打印当前窗体
- 如何在C#Winform程序中正确使用登录窗体
- c#窗体编程之建立时钟程序显示当前时间
- c# winForm 将窗体状态栏StatusStrip 分成左中右三部分 右边显示当前时间
- 如何 对 Windows 窗体控件进行线程安全调用
- C#中如何去除窗体默认的关闭按钮?
- 如何用C#和SQL获得当前月的第一天和最后一天
- 【转载】ARX如何得到当前CAD打印设备列表及其他打印设置内容
- c#如何将txt文本内容进行清空(C#清空txt文本内容)