首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PrintDialog.PrinterSettings不工作

PrintDialog.PrinterSettings不工作
EN

Stack Overflow用户
提问于 2013-10-11 08:43:52
回答 1查看 1.8K关注 0票数 3

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

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

代码语言:javascript
复制
//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);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2013-10-11 09:02:30

在这段代码中,您使用了两种打印方法。

  1. 第一个方法,使用PrintDialog,它不能在您的情况下工作,因为您必须设置Document属性。
  2. 第二种方法,使用Process类和所有页面打印,因为您在参数处将整个文件发送到打印机。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19313868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档