日期:2014-05-20  浏览次数:20473 次

在asp.net+c#的环境下,如何实现套打?
有个变量str,希望通过点击网页上的一个BUTTON在指定的位置(0,50)上打印出来,就像在VC下的TextOut(dc,0,50,str,4);本人试着写了一下,但不成功,请指教.
//打印测试
private   string   printBuffer= "Print   Test! ";
private   Font   printFont;
private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
      try
      {
                  System.Drawing.Printing.PrintDocument   pd=new   System.Drawing.Printing.PrintDocument();
System.Windows.Forms.PrintDialog   dlg=new   System.Windows.Forms.PrintDialog();
dlg.Document=pd;
                  printFont=new   Font( "Arial ",10);
                  pd.PrintPage+=new   PrintPageEventHandler(this.pd_PrintPage);
System.Windows.Forms.DialogResult   result=dlg.ShowDialog();
if(result==System.Windows.Forms.DialogResult.OK)
pd.Print();
        }
        catch(Exception   Ex)
        {
Response.Write(Ex.ToString());
        }
}
private   void   pd_PrintPage(object   sender,PrintPageEventArgs   ev)
{
float   lpp=0;
float   yPos=0;
float   leftMargin=ev.MarginBounds.Left;
float   topMargin=ev.MarginBounds.Top;

lpp=ev.MarginBounds.Height/printFont.GetHeight(ev.Graphics);
ev.Graphics.DrawString(printBuffer,printFont,Brushes.Black,leftMargin,yPos,new   StringFormat());
ev.HasMorePages=false;
}

------解决方案--------------------
不会.帮你顶
------解决方案--------------------
我也需要解决这个问题
关注一吓
------解决方案--------------------
up