Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been using this printdialog command before and their's no problem when I'm gonna print I can choose what page/s I want and choosing the specific pages then print it .

This my codes:
C#
using (var dlg = new PrintDialog())
{
   // configure dialog
   dlg.AllowSomePages = true;
   dlg.AllowSelection = true;
   dlg.UseEXDialog = true;
   dlg.Document = Document;

   // show allowed page range
   var ps = dlg.PrinterSettings;
   ps.MinimumPage = ps.FromPage = 1;
   ps.MaximumPage = ps.ToPage = 2;

   // show dialog
   if (dlg.ShowDialog(this) == DialogResult.OK)
   {
      //  print selected page range
      _preview.Print();
   }
}

Later on I change the printdialog and i used the combobox to get the available printers then the printbutton w/out the printdialog, but my problem is all pages must be printed and and not the page I set in the Frompage and Topage.
Is there anybody would like to help me ? :(

Here's my codes:
C#
using (var dlg = new PrintDialog())
{
   // configure dialog
   dlg.AllowSomePages = true;
   dlg.AllowSelection = true;
   dlg.UseEXDialog = true;
   dlg.Document = Document;

   // show allowed page range
   var ps = dlg.PrinterSettings;
   ps.MinimumPage = ps.FromPage = 1;
   ps.MaximumPage = ps.ToPage = 2;
   ps.Copies = Convert.ToInt16(numericUpDown1.Value);

   ps.PrinterName = cbox.SelectedItem.ToString();
   _preview.Print();
}



[edit]Code block added[/edit]
Posted
Updated 15-Feb-14 1:33am
v3
Comments
Nelek 15-Feb-14 7:39am    
If the document is bigger than 2 pages, why are you limiting it? Have you tried to give other values into "MinimumPage" and "MaximumPage"?
Member 10332274 15-Feb-14 7:45am    
I set that because, I want only to print the first and second pages. But all 5pages would be printed instead of 1 and 2 only
Nelek 15-Feb-14 7:58am    
You told: "but my problem is all pages must be printed and and not the page I set in the Frompage and Topage."

So... what is the real problem?
Option 1) You want to print all pages and only get printed 1 and 2?
Option 2) You want to print pages 1 and 2, but you are getting all pages printed?
Member 10332274 15-Feb-14 8:18am    
Yeah! Not necessarily the 1st and 2nd pages, I want to print the specific that I want to be printed.
Like this I've changed some of my codes but it doesn't work!

ps.MinimumPage = ps.FromPage = Convert.ToInt16(n1.Value);
ps.MaximumPage = ps.ToPage = Convert.ToInt16(n2.Value);
Nelek 15-Feb-14 8:38am    
:doh: :wtf: I give up

1 solution

after you add choosing printer name to your code you must add this code :



C#
ps.PrintRange = System.Drawing.Printing.PrintRange.Selection;



and for more , add the if statement at the end before printing command
 
Share this answer
 
Comments
Member 10332274 15-Feb-14 8:40am    
What would be the if statement I add?
M.Hazzouri 15-Feb-14 8:50am    
if (dlg.ShowDialog(this) == DialogResult.OK)
{
// print selected page range
_preview.Print();
}

i mean this ,
Member 10332274 15-Feb-14 9:05am    
Yeah! That's the code I've used before, try to read my post. Now I'm trying not to used the printdialog to show but to have it manually by using the combobox to get the printerlist and button to print it directly by not using the printdialog to show.
M.Hazzouri 15-Feb-14 9:33am    
oh yeah !! i'm sorry but try the code for (printing range)
Member 10332274 15-Feb-14 10:03am    
After the print range? what's next?

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