我正在尝试从 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);
}
}