如何编写代码将表单直接打印到打印机 [英] How to write code to print the form directly to the printers
本文介绍了如何编写代码将表单直接打印到打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请提供任何紧急代码。
谢谢,
Surender
解决方案
以下是Microsoft的C#示例:
此示例演示如何打印当前表单的副本。
[System.Runtime.InteropServices.DllImport( gdi32.dll)]
public static extern long BitBlt( IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight,< span class =code-sdkkeyword> IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private 位图memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = < span class =code-keyword> this .CreateGraphics();
尺寸s = 此 .Size;
memoryImage = new 位图(s.Width,s.Height,mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0 , 0 ,此 .ClientRectangle.Width,此 .ClientRectangle.Height,dc1, 0 , 0 , 13369376 );
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System。对象发件人,System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0 , 0 );
}
私有 void printButton_Click(系统。 Object sender,System.EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
祝你好运,
C
Give any code its urgent please.
Thanks,
Surender
解决方案
Here's a C# example from Microsoft:
This example demonstrates printing a copy of the current form.
[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(); printDocument1.Print(); }
Good luck,
C
这篇关于如何编写代码将表单直接打印到打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文