有个变量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;
}