Click here to Skip to main content
15,897,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get number of copy user enter at run time from printDialog ??

My code is -:

C#
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();
                    }
                }
}


when the user enter 4 copy of invoice to print, the String array print his one value on every page...
Posted
Updated 10-Mar-13 3:55am
v2
Comments
Michael Haephrati 9-Mar-13 14:21pm    
current page number and number of copies are 2 different things
JayantaChatterjee 9-Mar-13 14:26pm    
I want both number of copy and current page number..
I already get the number of copy by printDialog1.PrinterSettings.Copies .
Now only want the current page number(before print that page)??
CHill60 9-Mar-13 15:17pm    
Not sure what you mean by current page number - are you trying to get feedback as each page is printed?
JayantaChatterjee 9-Mar-13 21:19pm    
I created a invoice application, when the user want to print 1 or more copies of invoice, I want print on every Copy name on every page(like Original copy,Duplicate copy ctc...)..
Sir I'm using printDocument and printDialog...
Please Tell me how to do this???

1 solution

You have several properties to use, like:
SQL
With PrintDialog1
         .AllowCurrentPage = True;
         .AllowSomePages = True;
         .AllowPrintToFile = True;
         .AllowSelection = True;
         .ShowDialog();
End With


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


[EDIT]
OK, now i'm getting, what you want.

Please, see below example:
C#
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);

        }
    }
}


I hope this is what you want ;)

[/EDIT]

[EDIT 2]
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]
 
Share this answer
 
v3
Comments
JayantaChatterjee 9-Mar-13 21:22pm    
I created a invoice application, when the user want to print 1 or more copies of invoice, I want print on every Copy name(like Original copy,Duplicate copy etc...) on every page..
Sir I'm using printDocument and printDialog...
Please Tell me how to do this???
Maciej Los 10-Mar-13 6:58am    
CHill60 10-Mar-13 7:23am    
My 5 - I was going to suggest the QueryPageSettings event on the same class
Maciej Los 10-Mar-13 7:31am    
Thank you Caroline ;)
Good suggestion.
JayantaChatterjee 10-Mar-13 8:18am    
but sir QueryPageSettings event can change the page size and cancel the print, it doesn't allow to drawString on printDocument.
how to add different copy name on every print pages??
can you give me the code by which I can drew different String on different page..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900