为什么什么也打不出?
代码如下:
private void btnPrint_Click(object sender, System.EventArgs e)
{
try
{ PrintDialog pdl = new PrintDialog();
PrintDocument pd = new PrintDocument();
pdl.Document = pd;
DialogResult dr = pdl.ShowDialog(this);
if(pdl.PrinterSettings.PrinterName=="<无默认打印机>")
{
MessageBox.Show("无默认打印机");
return;
}
if(dr==DialogResult.OK)
{
pd.PrinterSettings.PrinterName =pdl.PrinterSettings.PrinterName;
pd.PrintPage+=new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void pd_PrintPage(object sender,PrintPageEventArgs ev)
{
Font pd_font=new System.Drawing.Font(FontFamily.Families[0],1);
Color pd_color =new System.Drawing.Color();
Brush pd_brush =
new System.Drawing.SolidBrush(System.Drawing.Color.Black);
PointF pd_pointf=
new System.Drawing.PointF(30,30);
ev.Graphics.DrawString
( "It is a test",pd_font,pd_brush,pd_pointf);
}