为什么什么也打不出?

LeonardoDiCaprio 2003-09-12 10:51:41
代码如下:
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);
}
...全文
90 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LeonardoDiCaprio 2003-09-12
  • 打赏
  • 举报
回复
TO sqhua(拉长弓兮射天狼)
程序能正确运行
就是打不出东西
sqhua 2003-09-12
  • 打赏
  • 举报
回复
to wkyjob(流星划過...):
>>else(dr==DialogResult.OK)
是错误的语法!

楼主Debug一下代码,看程序能走到什么地方
LeonardoDiCaprio 2003-09-12
  • 打赏
  • 举报
回复
TO wkyjob(流星划過...)
效果是一样的
wkyjob 2003-09-12
  • 打赏
  • 举报
回复
if(pdl.PrinterSettings.PrinterName=="<无默认打印机>")
{
MessageBox.Show("无默认打印机");
return;

}
else(dr==DialogResult.OK)
{
pd.PrinterSettings.PrinterName =pdl.PrinterSettings.PrinterName;
pd.PrintPage+=new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
LeonardoDiCaprio 2003-09-12
  • 打赏
  • 举报
回复
To All
我的问题已经解决了
谢谢各位

lyrixliu 2003-09-12
  • 打赏
  • 举报
回复

if(dr==DialogResult.OK)
设置断点,跟踪一下看看

我估计if(pdl.PrinterSettings.PrinterName=="<无默认打印机>")有问题
程序可能没有运行到打印部分;

另外调试时看一下printersettings的属性,看看打印机设置是否有问题

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧