Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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();
                    }
                }
}
 
when the user enter 4 copy of invoice to print, the String array print his one value on every page...
Posted 9-Mar-13 9:09am
Edited 10-Mar-13 4:55am
v2
Comments
Michael Haephrati at 9-Mar-13 14:21pm
   
current page number and number of copies are 2 different things
Jayanta Chatterjee at 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 at 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?
Jayanta Chatterjee at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You have several properties to use, like:
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:
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 Wink | ;)
 
[/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]
  Permalink  
v3
Comments
Jayanta Chatterjee at 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 at 10-Mar-13 6:58am
   
CHill60 at 10-Mar-13 7:23am
   
My 5 - I was going to suggest the QueryPageSettings event on the same class
Maciej Los at 10-Mar-13 7:31am
   
Thank you Caroline ;)
Good suggestion.
Jayanta Chatterjee at 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..
Maciej Los at 10-Mar-13 8:32am
   
Improve your solution and provide more details. Show your code. Without knowing what exactly do you print, how can i help you?
Have you seen examples on msdn (did you follow above links)?
Jayanta Chatterjee at 10-Mar-13 9:56am
   
yes sir, I follow every links..
I Improve my question...
Please check it ..
Espen Harlinn at 10-Mar-13 18:29pm
   
Nice effort :-D
Maciej Los at 10-Mar-13 18:30pm
   
Thank you, Espen ;)

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

  Print Answers RSS
0 OriginalGriff 584
1 Maciej Los 275
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 10 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100