表格打印选择 [英] Form Printing choices
问题描述
我有一个模板(纸卡")产品详细信息票证,并且我设计了一个C#应用程序窗体,该窗体使用标签和文本框以及TableLayoutPanel与其大小和外观完全匹配.
我要做的是打印应该看起来像纸质模板的表格内容.
知道我没有拥有一个数据库或大约一个数据库,并且手动填充了文本框,我在实现此任务时需要做哪些选择,以及在这种情况下的最佳实践是什么? h2_lin>解决方案
当我需要从WinForms程序进行打印时,我将PrintDocument控件与
PrintPreviewDialog和
PageSetupDialog一起使用.您没有说要使用哪种类型的应用程序,但这也许会有所帮助.
您没有说过如何复制纸质表格,但是如果它在屏幕上,请注意打印机的像素大小不同,等等,因此您可能需要进行一些调整.
使用此代码
添加PrintPreviewDialog&表格上的PrintDocument
将Printdocument分配给printPreviewdialog
然后使用以下代码
[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(); }
I have a template ("paper card") product details ticket , and I have designed a C# app form that exactly matches it''s size and looks, using labels and textboxes and TableLayoutPanel.
What I want to do is printing the contents of the form which is supposed to look exactly like the paper template.
What are the choices that I have to achieve this task and what is the best practice in this situation knowing that I do NOT have a database or so , and the textboxes are filled manually.
I use thePrintDocumentcontrol along with
PrintPreviewDialogand
PageSetupDialogwhen I need to do printing from a WinForms program. You didn''t say what type of app you are working on, but perhaps that will help.
You didn''t say how you duplicated the paper form, but if it''s on the screen, please be aware that the printer has different pixel sizes, etc. so you may have to do some adjustments.
Use this code
Add PrintPreviewDialog & PrintDocument on form
Assign Printdocument to printPreviewdialog
then use following code
[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(); }
这篇关于表格打印选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!