认真工作,天天向上

不断的学习,不断的总结

导航

C# 印刷类

         最近一个新的项目中,有一个要求,就是把数据打印出来。经过调查,写了一个类。
主要应用了 System.Drawing
Pint为主要方法 参数是将要打印的结果。
 public void Print(CmDCardPrintData argDcardData)
        
{
            Thread.CurrentThread.CurrentCulture 
=
                CultureInfo.CreateSpecificCulture(
"en-US");

            printData 
= argDcardData;

            
bool isToBitmap = Boolean.Parse(reportSettings["print.toBitmap"]);
            
string bitmapSaveDir = reportSettings["print.bitmapSaveDir"];

            
string printerName = reportSettings["print.printerName"];

            mCode39Format 
= reportSettings["print.CODE39.Format"];

            leftMargin 
= Int32.Parse(reportSettings["print.leftMargin"]);
            topMargin 
= Int32.Parse(reportSettings["print.topMargin"]);

            
if (isToBitmap)
            
{
                
for debug. print to bitmap image.
            }

            
else
            
{
                
print to printer
            }


        }

 private void Pd_PrintPage(object sender, PrintPageEventArgs ev)
        
{

            PrintData(ev.Graphics, ev.MarginBounds.Left, ev.MarginBounds.Top);

            ev.HasMorePages 
= false;
        }

 private void DrawText(Graphics g, string curField,string text)
        
{
            g.TranslateTransform(leftMargin 
+ fieldInfos[curField].Left, topMargin + fieldInfos[curField].Top);
            g.ScaleTransform(
1.0F, fieldInfos[curField].VerticalRatio);

            g.DrawString(text,
               fieldInfos[curField].Font, Brushes.Black,
                
00);

            
// reset matrix 
            g.ResetTransform();
        }
打印的结果图:

posted on 2007-07-10 11:00  MYOOP  阅读(627)  评论(2编辑  收藏  举报