zoukankan      html  css  js  c++  java
  • C# WinForm 打印窗体

    在WinForm中打印窗体代码,使用屏幕截图再打印:

    [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, 00this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0013369376);
       mygraphics.ReleaseHdc(dc1);
       memoryGraphics.ReleaseHdc(dc2);
    }
    private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
       e.Graphics.DrawImage(memoryImage, 00);
    }
    private void printButton_Click(System.Object sender, System.EventArgs e)
    {
       CaptureScreen();
       printDocument1.Print();
    }
  • 相关阅读:
    Mysql 修改默认端口
    通过.pro文件生成C++工程
    内联函数知识点
    DICOM文件添加私有Tag(DCMTK Private Tag)
    poj 1185 炮兵阵地 状压dp
    cf #216 C
    cdoj1365 木杆上的蚂蚁
    cf #214 Dima and Salad
    cf #213 Matrix
    hdu 2222 Keywords Search(AC自动机入门题)
  • 原文地址:https://www.cnblogs.com/dingshouqing/p/2217194.html
Copyright © 2011-2022 走看看