本文介绍了如何从c#中的printdialog获取当前页码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从printDialog获取运行时输入的复制用户数?



我的代码是 - :



how to get number of copy user enter at run time from printDialog ??

My code is -:

string[] strCopy;//I declare it as a Global Variable
//and initialize in formLoad event
strCopy = new string[4];
            strCopy[0] = "ORIGINAL COPY";
            strCopy[1] = "DUPLICATE COPY";
            strCopy[2] = "TRIPLICATE COPY";
            strCopy[3] = "QUADRUPLICATE COPY";
//Here's printPage event 

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

                e.Graphics.DrawString(strCopy[numOfCopy--], new Font("Arial", 9, FontStyle.Underline), Brushes.Black, 350, 30);  
                e.Graphics.DrawString("Phone No.:- " + phoneBox18.Text, new Font("Arial", 10,FontStyle.Bold), Brushes.Black, 30, 30);
                e.Graphics.DrawString(textBox1.Text, new Font("Arial", 10, FontStyle.Bold), Brushes.Black, 400, 70);
                e.Graphics.DrawString(textBox2.Text, new Font("Arial", 9), Brushes.Black, new Rectangle(390, 100, 370, 50));
                e.Graphics.DrawString(textBox3.Text, new Font("Arial", 9), Brushes.Black, 490, 160);
               
}

//when the printDialog is called
private void button2_Click(object sender, EventArgs e)
        {
DialogResult dr = MessageBox.Show("Do You Want to Print?", "Print", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    printDocument1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 830, 1070);
                    printDocument1.PrinterSettings.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 830, 1070); ;
                    printDialog1.Document = printDocument1;
                    numOfCopy = printDialog1.PrinterSettings.Copies;
                    if (printDialog1.ShowDialog() == DialogResult.OK)
                    {                        
                        printDocument1.Print();
                    }
                }
}





当用户输入4份发票复印件时,字符串数组在每个页面打印一个值...



when the user enter 4 copy of invoice to print, the String array print his one value on every page...

推荐答案

With PrintDialog1
         .AllowCurrentPage = True;
         .AllowSomePages = True;
         .AllowPrintToFile = True;
         .AllowSelection = True;
         .ShowDialog();
End With





更多关于:

[]

[ [ ]

[]







好​​的,现在我得到了,你想要的。



请看下面的例子:



More about:
PrintDialog Class[^]
PrintDialog Properties[^]
AllowCurrentPage[^]
AllowSomePages[^]



OK, now i''m getting, what you want.

Please, see below example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public int numcopies = 0;
        public int currcopy = 0;
        public string[] strCopy = new string[] {"ORIGINAL COPY", "DUPLICATE COPY","TRIPLICATE COPY","QUADRUPLICATE COPY"};

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //print document
            System.Drawing.Printing.PrintDocument pdoc = new System.Drawing.Printing.PrintDocument();
            pdoc.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 830, 1070);
            pdoc.PrinterSettings.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 830, 1070); ;
            //add event handler
            pdoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pdoc_PrintPage);
            DialogResult res = DialogResult.Cancel;
            System.Windows.Forms.PrintDialog pdlg = new PrintDialog();
            pdlg.AllowCurrentPage = true;
            pdlg.AllowPrintToFile = true;
            pdlg.Document = pdoc;
            res = pdlg.ShowDialog();
            if (res == DialogResult.OK)
            {
                //ignore number of copies set by user; number of copies if const ;)
                numcopies = 4;
            };
            //print 4 copies
            for (int i = 1; i<numcopies+1 ;i++ )
            {
                currcopy = i-1;
                pdoc.DocumentName = strCopy[currcopy].ToString();
                pdoc.Print();
            }


        }

        // The PrintPage event is raised for each page to be printed. 
        private void pdoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawString(strCopy[currcopy ].ToString(), new Font("Arial", 9, FontStyle.Underline), Brushes.Black, 350, 30);
            e.Graphics.DrawString(this.textBox1.Text, new Font("Arial", 10, FontStyle.Italic), Brushes.Black, 30, 30);
            e.Graphics.DrawString(this.textBox2.Text, new Font("Arial", 10, FontStyle.Bold), Brushes.Black, 400, 70);
            e.Graphics.DrawString(this.textBox3.Text, new Font("Arial", 9), Brushes.Black, new Rectangle(390, 100, 370, 50));
            e.Graphics.DrawString(this.textBox4.Text, new Font("Arial", 9), Brushes.Black, 490, 160);

        }
    }
}





我希望这是你想要的; )



[/ EDIT]





提示/提示:

添加4个复选框的自定义对话框(窗体)会很棒:

- oryginal

- 1.复制

- 2.复制

- 3.复制

取决于用户选择,程序应该只打印选定的副本。

[/ EDIT]



I hope this is what you want ;)

[/EDIT]


Tip/Hint:
It would be great to add custom dialogbox (windows form) with 4 checkboxes:
- oryginal
- 1. copy
- 2. copy
- 3. copy
Depends on user selection, program should print only selected copies.
[/EDIT]


这篇关于如何从c#中的printdialog获取当前页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:28