问题描述
我在打印机上定义了几种自定义纸张尺寸(打印机设置为默认值).我需要能够选择其中一种格式作为默认格式.
I have several custom paper sizes defined on a printer(the printer is set as default). I need to be able to select one of these formats as the default one.
编程(C#)解决方案是理想的,但命令行解决方案也可以.
A programmatic(C#) solution would be ideal, but a command line one would be ok too.
现在,我可以获取打印机上定义的纸张尺寸(名称/尺寸)列表,并且可以找出哪个是默认值.
Right now, I am able to get the list of paper sizes(name/dimensions) defined on the printer, and I can find out which one is the default.
为了选择另一种格式作为默认格式,我目前唯一的解决方案是更改 devMode 结构上的 dmPaperSize 字段;但是我找不到与所需纸张格式相对应的正确值.所以我将 dmPaperSize 设置为 0,并增加它,直到正确的格式出现在打印机上.这在某些打印机上需要很长时间.
In order to select another format as default, the only solution I have so far is by changing the dmPaperSize field on the devMode structure; BUT I cannot find out the correct value that corresponds to the desired paper format. So I set dmPaperSize to 0, and increment it, until the correct format appears on the printer. This takes a very long time on some printers.
是否有另一种方法来选择(按名称)默认打印机上的默认纸张格式?
Is there another way to select(by name) the default papaer format on the default printer ?
推荐答案
更改默认打印机设置的方向是正确的..NET 不直接支持更改打印机的默认设置.
You are in the right direction in changing the default printer settings. .NET doesn't provide direct support to change the default settings of a printer.
我使用了 thisPrinterSettings 类> codeproject 文章更改打印机设置.
I used the PrinterSettings class from this codeproject article to change the printer settings.
可以使用 PrintDocument.PrinterSettings 检索打印机中可用的纸张尺寸.请参阅下面的示例代码以从打印机中检索可用的纸张尺寸并使用 PaperSize.RawKind 更改打印机的纸张尺寸.
The available paper sizes from the printer can be retrieved using the PrintDocument.PrinterSettings. See the sample code below for retrieving the available papersizes from the printer and using the PaperSize.RawKind for changing the papersize of the printer.
public class PrinterSettingsDlg : Form
{
PrinterSettings ps = new PrinterSettings();
Button button1 = new Button();
ComboBox combobox1 = new ComboBox();
public PrinterSettingsDlg()
{
this.Load += new EventHandler(PrinterSettingsDlg_Load);
this.Controls.Add(button1);
this.Controls.Add(combobox1);
button1.Dock = DockStyle.Bottom;
button1.Text = "Change Printer Settings";
button1.Click += new EventHandler(button1_Click);
combobox1.Dock = DockStyle.Top;
}
void button1_Click(object sender, EventArgs e)
{
PrinterData pd = ps.GetPrinterSettings(PrinterName);
pd.Size = ((PaperSize)combobox1.SelectedItem).RawKind;
ps.ChangePrinterSetting(PrinterName, pd);
}
void PrinterSettingsDlg_Load(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = // printer name
combobox1.DisplayMember = "PaperName";
foreach (PaperSize item in pd.PrinterSettings.PaperSizes)
{
combobox1.Items.Add(item);
}
}
}
这篇关于更改打印机默认纸张大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)