C#中打印时选择打印机的问题。

crazyzyc 2010-04-28 09:16:39
我用printDialog的调出打印窗口时,没有办法选择其他打印机,只能用默认的 请问该如何解决这个问题?

private void button2_Click(object sender, EventArgs e)
{
if (!IsWholeNumber(this.txtNum.Text.Trim()))
{
MessageBox.Show("Please enter a number!", "提交提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtNum.Focus();
txtNum.SelectAll();
label8.Visible = true;
return;
}

if (printDialog1.ShowDialog() != DialogResult.Cancel)
{
try
{
printDocument1.Print();
p = 1;
totalNo = 0;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}
}
...全文
1451 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复
printDocument1.Print();
crazyzyc 2010-04-28
  • 打赏
  • 举报
回复
晓得了,谢谢

string pname=this.printDialog1.PrinterSettings.PrinterName;
printDocument1.PrinterSettings.PrinterName = pname;
printDialog1.Document = printDocument1;
printDocument1.Print();
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 crazyzyc 的回复:]

引用 9 楼 computerfox 的回复:
那是示例代码,最主要的是,通过设置一下printDialog1.Document=this.printDocument1再去显示printDialog1时,就能选择打印机了。选择的打印机可以通过这样的方式取到其名称:

C# code
string PrinterName = this.printDocument1.PrinterSetti……
[/Quote]
你要打印什么?
jy315189 2010-04-28
  • 打赏
  • 举报
回复
学习学习
crazyzyc 2010-04-28
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 computerfox 的回复:]
那是示例代码,最主要的是,通过设置一下printDialog1.Document=this.printDocument1再去显示printDialog1时,就能选择打印机了。选择的打印机可以通过这样的方式取到其名称:

C# code
string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
[/Quote]
能将的详细一些吗?我现在能弹出选择打印机的对话框,但取得打印机名称后该如何用设定的打印机打印?
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复
那是示例代码,最主要的是,通过设置一下printDialog1.Document=this.printDocument1再去显示printDialog1时,就能选择打印机了。选择的打印机可以通过这样的方式取到其名称:
string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
crazyzyc 2010-04-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 computerfox 的回复:]
这样肯定可以了!

C# code

//Open the PrintDialog
this.printDialog1.Document = this.printDocument1;
DialogResult dr = this.printDialog1.ShowDialog();
if……
[/Quote]
这几行代码是做什么的?那几个INT变量有用吗?
crazyzyc 2010-04-28
  • 打赏
  • 举报
回复
谢谢各位,我先试试啊
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复
拖一个PrintDocument控件和PrintDialog控件上去,然后设置一下printDialog1.Document=this.printDocument1再去显示printDialog1时,就有了。
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复
这样肯定可以了!

//Open the PrintDialog
this.printDialog1.Document = this.printDocument1;
DialogResult dr = this.printDialog1.ShowDialog();
if(dr == DialogResult.OK)
{
//Get the Copy times
int nCopy = this.printDocument1.PrinterSettings.Copies;
//Get the number of Start Page
int sPage = this.printDocument1.PrinterSettings.FromPage;
//Get the number of End Page
int ePage = this.printDocument1.PrinterSettings.ToPage;
string PrinterName = this.printDocument1.PrinterSettings.PrinterName;

g394594141 2010-04-28
  • 打赏
  • 举报
回复
computerfox回答得很好,他说的应该可以实现。

还有种就是你先调用Api把默认打印机设置成你要用的打印机
皇城龙三 2010-04-28
  • 打赏
  • 举报
回复
应该有选择窗口,你弹出来的窗口是什么?



用printsetting.Add(prt.PrinterSettings.PrinterName),看看有没有其他打印机
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复
试试看设置这个属性能不能用?

this.printDialog1.PrinterSettings.PrinterName
捷哥1999 2010-04-28
  • 打赏
  • 举报
回复

pageSetupDialog1.PageSettings = new System.Drawing.Printing.PageSettings();
if (DialogResult.OK == this.pageSetupDialog1.ShowDialog())
{
this.printDialog1.PrinterSettings = pageSetupDialog1.PrinterSettings;
}

使用pageSetupDialog1先让用户选择好参数后,传递给printDialog1

111,077

社区成员

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

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

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