【问题标题】:Print number of copies depending on the textbox input and put page numbers C#根据文本框输入打印份数并放置页码C#
【发布时间】:2017-04-27 17:02:14
【问题描述】:

请帮助我是 C# 新手,我有一个带有 textbox1、textbox2 和 buttom1 的 windows 窗体我想打印 textbox1 的值而不预览,或者让我直接对打印机说没有任何交互,文本框值必须是我想打印的 capies 的数量以及页码所有这些副本都说如果我输入 3 它应该说 page 1/3 2/3 3/3 请帮助并原谅我的英语 我的按钮下有以下代码

private void button1_Click(object sender, EventArgs e)
    {


        PrintDocument printDocument = new PrintDocument();
        printDocument.DefaultPageSettings.Landscape = true;
        printDocument.DefaultPageSettings.PaperSize = new PaperSize("zed", 400, 850 );
        //printDocument.PrinterSettings.Copies = 2;
        printDocument.PrintPage += PrintDocumentOnPrintPage;
        printDocument.Print();

【问题讨论】:

  • 查看int.TryParse - 如果将文本值转换为 int 成功则返回 true,否则返回 false。您可以获取文本框值并将其转换为整数以传递给 .Copies :)
  • 好的,非常感谢约翰确实将其转换为并通过研究进行了研究,因为我声明我对这些东西不熟悉 int i = 0; i = Convert.ToInt32(textBox2.Text); textBox2.Text = i.ToString();所以将它传递给 .copies 对我来说是一件麻烦事,因为它说我隐含地将 int 传递给 short 请帮助我如何将它传递给 .copies

标签: c#


【解决方案1】:

我确实解决了 .copies 问题,但仍然无法解决页码问题,这是我现在的代码

 private void button1_Click(object sender, EventArgs e)
    {
        short numCopies = 0;
        numCopies = Convert.ToInt16(textBox2.Text);


        PrintDocument printDocument = new PrintDocument();
        printDocument.DefaultPageSettings.Landscape = true;
        printDocument.DefaultPageSettings.PaperSize = new PaperSize("zed", 400, 850 );
        printDocument.PrinterSettings.Copies = numCopies;
        printDocument.PrintPage += PrintDocumentOnPrintPage;
        printDocument.Print();

    }    

【讨论】:

    猜你喜欢
    • 2020-03-29
    • 2017-08-09
    • 2016-12-04
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 2017-11-01
    • 1970-01-01
    相关资源
    最近更新 更多