gpt4 book ai didi

c# - PrintDialog.PrinterSettings 不工作

转载 作者:行者123 更新时间:2023-11-30 18:31:56 33 4
gpt4 key购买 nike

我正在尝试从 datagridview 打印选定的文件。此文件位置保存在数据库中。现在在打印之前我想将“份数,从页面到页面”传递给 PrintDialog。我能够将这些值传递给 PrintDialog,但它不起作用,所有页面都在打印,而且也只打印一次。我什至在网上搜索了很多,但无法解决这个问题。

请通过选择所有页面选项或将值传递给 FromPage 和 ToPage 来帮助我打印“n”份。我的代码是:

//string ASSIGNMENT_PATH = dataGridView1.Rows[k].Cells[2].Value.ToString();
string ASSIGNMENT_PATH = "@C:\test.docx";

if (!File.Exists(ASSIGNMENT_PATH))
{
MessageBox.Show("No exceptional file created by application till now .");
}
else
{
short noC = Convert.ToInt16(txtNumOfCopies.Text);
short fP = Convert.ToInt16(txtFromPage.Text);
short tP = Convert.ToInt16(txtToPage.Text);

PrintDialog dialog = new PrintDialog();
dialog.AllowSomePages = true;
dialog.PrinterSettings.FromPage = fP;
dialog.PrinterSettings.ToPage = tP;
dialog.PrinterSettings.Copies = noC;

DialogResult dialogResult = dialog.ShowDialog(this);

if (dialogResult == DialogResult.Cancel)
{
this.Close();
}
if (dialogResult == DialogResult.OK)
{
ProcessStartInfo info = new ProcessStartInfo(ASSIGNMENT_PATH);
info.Verb = "PrintTo";
info.Arguments = "\"" + printDialog1.PrinterSettings.PrinterName + "\"";
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
}
}

最佳答案

在此代码中,您使用了 2 种打印方法。

  1. 第一种方法,使用 PrintDialog,它不适用于您的情况,因为您必须设置 Document 属性。

  2. 第二种方法,使用 Process 类并打印所有页面,因为您在参数处将整个文件发送到打印机。

它是打印 DataGridView 的示例 http://www.codeproject.com/Articles/28046/Printing-of-DataGridView或者你也可以试试这个 How to print values from a DataGridView control

关于c# - PrintDialog.PrinterSettings 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19313868/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com