How to print a preview for current forms in C #

zhaozj2021-02-16  47

[System.Runtime.Interopservices.dllimport ("gdi32.dll")]]

Public Static Extern long bitblt (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 ();

}

转载请注明原文地址:https://www.9cbs.com/read-22556.html

New Post(0)