使用printdialogbox或printdialog命令打印 [英] Printing with out printdialogbox or printdialog command
问题描述
我以前一直在使用这个printdialog命令,当我要打印时没问题我可以选择我想要的页面然后选择特定页面然后打印它。
这是我的代码:
I've been using this printdialog command before and their's no problem when I'm gonna print I can choose what page/s I want and choosing the specific pages then print it .
This my codes:
using (var dlg = new PrintDialog())
{
// configure dialog
dlg.AllowSomePages = true;
dlg.AllowSelection = true;
dlg.UseEXDialog = true;
dlg.Document = Document;
// show allowed page range
var ps = dlg.PrinterSettings;
ps.MinimumPage = ps.FromPage = 1;
ps.MaximumPage = ps.ToPage = 2;
// show dialog
if (dlg.ShowDialog(this) == DialogResult.OK)
{
// print selected page range
_preview.Print();
}
}
后来我改变了printdialog,我使用了组合框来获得可用的打印机,然后打印按钮带出了printdialog,但我的问题是所有页面都必须打印,而不是我在Frompage和Topage中设置的页面。
有人想帮助我吗? :(
这是我的代码:
Later on I change the printdialog and i used the combobox to get the available printers then the printbutton w/out the printdialog, but my problem is all pages must be printed and and not the page I set in the Frompage and Topage.
Is there anybody would like to help me ? :(
Here's my codes:
using (var dlg = new PrintDialog())
{
// configure dialog
dlg.AllowSomePages = true;
dlg.AllowSelection = true;
dlg.UseEXDialog = true;
dlg.Document = Document;
// show allowed page range
var ps = dlg.PrinterSettings;
ps.MinimumPage = ps.FromPage = 1;
ps.MaximumPage = ps.ToPage = 2;
ps.Copies = Convert.ToInt16(numericUpDown1.Value);
ps.PrinterName = cbox.SelectedItem.ToString();
_preview.Print();
}
[edit]已添加代码块[/编辑]
[edit]Code block added[/edit]
推荐答案
在您的代码中添加选择打印机名称后,您必须添加以下代码:
after you add choosing printer name to your code you must add this code :
ps.PrintRange = System.Drawing.Printing.PrintRange.Selection;
以及更多,在打印命令之前添加if语句
and for more , add the if statement at the end before printing command
这篇关于使用printdialogbox或printdialog命令打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!