473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access to a printDialog from a PrintPreviewDialog

Hello,

Is there a way to call a printDialog from a printPreviewDialog (from print
icon for example)?
Indeed, the print icon in the printpreviewdialog prints directly the
document without lunching the printdialog (i.e. the user can't choose the
print parameters).

Thanks a lot.
Nov 30 '06 #1
10 15286

choupi wrote:
Hello,

Is there a way to call a printDialog from a printPreviewDialog (from print
icon for example)?
Indeed, the print icon in the printpreviewdialog prints directly the
document without lunching the printdialog (i.e. the user can't choose the
print parameters).

Thanks a lot.
I ended up creating a File --Print... menu option that brings up the
print dialog.

One of the irritating things about the print preview dialog is that a
lot of things that you would want to change (like this particular
point) are "private" within the control and therefore not changeable. I
would have liked to have seen protected methods like
OnPrintButtonClick, etc, so that one could override the behaviour.

It would also have been nice to be able to hide / disable buttons on
the toolbar if we wanted to, even if the only way were to set a
PrintButtonEnabled property or something like that.

PrintPreviewDialog and TabControl are two of the hokier controls in
..NET. I hope that someday they'll revisit them and make much-needed
improvements.

Nov 30 '06 #2
Ok, so there's no way to add a new button in the toolbar I imagine ?!

"Bruce Wood" <br*******@canada.coma écrit dans le message de news:
11*********************@h54g2000cwb.googlegroups.c om...
>
choupi wrote:
>Hello,

Is there a way to call a printDialog from a printPreviewDialog (from
print
icon for example)?
Indeed, the print icon in the printpreviewdialog prints directly the
document without lunching the printdialog (i.e. the user can't choose the
print parameters).

Thanks a lot.

I ended up creating a File --Print... menu option that brings up the
print dialog.

One of the irritating things about the print preview dialog is that a
lot of things that you would want to change (like this particular
point) are "private" within the control and therefore not changeable. I
would have liked to have seen protected methods like
OnPrintButtonClick, etc, so that one could override the behaviour.

It would also have been nice to be able to hide / disable buttons on
the toolbar if we wanted to, even if the only way were to set a
PrintButtonEnabled property or something like that.

PrintPreviewDialog and TabControl are two of the hokier controls in
.NET. I hope that someday they'll revisit them and make much-needed
improvements.

Dec 1 '06 #3
Well, I just have found a simple way using Reflection, and it works
perfectly.
Let me know if you're interested.

Thanks.
Dec 1 '06 #4
We're interested!
Robin S.
---------------------------------
"choupi" <no**@none.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Well, I just have found a simple way using Reflection, and it works
perfectly.
Let me know if you're interested.

Thanks.

Dec 1 '06 #5
Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. using System.Reflection;
  4.  
  5. using System.Drawing;
  6.  
  7. using System.Drawing.Printing;
  8.  
  9. using System.Windows.Forms;
  10.  
  11. namespace Test
  12.  
  13. {
  14.  
  15. public class MyPrintPreviewDialog : System.Windows.Forms.PrintPreviewDialog
  16.  
  17. {
  18.  
  19. private ToolBarButton myPrintButton;
  20.  
  21. public MyPrintPreviewDialog() : base()
  22.  
  23. {
  24.  
  25. Type t = typeof(PrintPreviewDialog);
  26.  
  27. FieldInfo fi = t.GetField("toolBar1", BindingFlags.Instance |
  28. BindingFlags.NonPublic);
  29.  
  30. FieldInfo fi2 = t.GetField("printButton", BindingFlags.Instance |
  31. BindingFlags.NonPublic);
  32.  
  33. ToolBar toolBar1 = (ToolBar)fi.GetValue(this);
  34.  
  35. ToolBarButton printButton = (ToolBarButton)fi2.GetValue(this);
  36.  
  37.  
  38. printButton.Visible = false;
  39.  
  40.  
  41. myPrintButton = new ToolBarButton();
  42.  
  43. myPrintButton.ToolTipText = printButton.ToolTipText;
  44.  
  45. myPrintButton.ImageIndex = 0;
  46.  
  47.  
  48. ToolBarButton[] oldButtons = new ToolBarButton[toolBar1.Buttons.Count-1];
  49.  
  50. for(int i = 0 ; i < oldButtons.Length ; i++) oldButtons[i] =
  51. toolBar1.Buttons[i+1];
  52.  
  53.  
  54. toolBar1.Buttons.Clear();
  55.  
  56. toolBar1.Buttons.Add(myPrintButton);
  57.  
  58. for(int i = 0 ; i < oldButtons.Length ; i++)
  59. toolBar1.Buttons.Add(oldButtons[i]);
  60.  
  61. toolBar1.ButtonClick += new ToolBarButtonClickEventHandler(toolBar1_Click);
  62.  
  63. }
  64.  
  65. private void toolBar1_Click(object sender, ToolBarButtonClickEventArgs
  66. eventargs)
  67.  
  68. {
  69.  
  70. if (eventargs.Button == myPrintButton)
  71.  
  72. {
  73.  
  74. PrintDialog printDialog1 = new PrintDialog();
  75.  
  76. printDialog1.Document = this.Document;
  77.  
  78. if (printDialog1.ShowDialog() == DialogResult.OK) this.Document.Print();
  79.  
  80. }
  81.  
  82. }
  83.  
  84. }
  85.  
  86. }
  87.  
  88.  
  89.  
Dec 5 '06 #6
Thanks!
Robin S.
"choupi" <no**@none.comwrote in message
news:uW**************@TK2MSFTNGP02.phx.gbl...[quote]
Dec 5 '06 #7
thats quite interesting!!!

Thanks
-Srinivas.

choupi wrote:
Hello,

Is there a way to call a printDialog from a printPreviewDialog (from print
icon for example)?
Indeed, the print icon in the printpreviewdialog prints directly the
document without lunching the printdialog (i.e. the user can't choose the
print parameters).

Thanks a lot.
Dec 6 '06 #8
Thanks for the starting place for the code needed to add the
PrintDialog to PrintPreviewDialog. However, I came across a number of
issues when I tried to implement your code in VS2005 (did you write
your version under VS2003? Just curious...). Here is code that works
under VS2005:

Expand|Select|Wrap|Line Numbers
  1. public class MyPrintPreviewDialog :
  2. System.Windows.Forms.PrintPreviewDialog
  3. {
  4. private ToolStripButton myPrintButton;
  5. public MyPrintPreviewDialog ( ) : base ( )
  6. {
  7. Type t = typeof ( PrintPreviewDialog );
  8. FieldInfo fi = t.GetField ( "toolStrip1",
  9. BindingFlags.Instance | BindingFlags.NonPublic );
  10. FieldInfo fi2 = t.GetField ( "printToolStripButton",
  11. BindingFlags.Instance | BindingFlags.NonPublic );
  12. ToolStrip toolStrip1 =
  13. ( ToolStrip ) fi.GetValue ( this );
  14. ToolStripButton printButton =
  15. ( ToolStripButton ) fi2.GetValue ( this );
  16. printButton.Visible = false;
  17. myPrintButton = new ToolStripButton ( );
  18. myPrintButton.ToolTipText = printButton.ToolTipText;
  19. myPrintButton.ImageIndex = 0;
  20.  
  21. ToolStripItem [ ] oldButtons =
  22. new ToolStripItem [ toolStrip1.Items.Count ];
  23. for ( int i = 0; i < oldButtons.Length; i++ )
  24. oldButtons [ i ] = toolStrip1.Items [ i ];
  25.  
  26. toolStrip1.Items.Clear ( );
  27. toolStrip1.Items.Add ( myPrintButton );
  28. for ( int i = 0; i < oldButtons.Length; i++ )
  29. toolStrip1.Items.Add ( oldButtons [ i ] );
  30. toolStrip1.ItemClicked +=
  31. new ToolStripItemClickedEventHandler ( toolBar1_Click );
  32. }
  33.  
  34. private void toolBar1_Click ( object sender,
  35. ToolStripItemClickedEventArgs eventargs )
  36. {
  37. if ( eventargs.ClickedItem == myPrintButton )
  38. {
  39. PrintDialog printDialog1 = new PrintDialog ( );
  40. printDialog1.Document = this.Document;
  41. if ( printDialog1.ShowDialog ( ) == DialogResult.OK )
  42. this.Document.Print ( );
  43. }
  44. }
  45. }

Thanks again for your inspiration.
Jan 15 '07 #9
Thx!! this was very useful !

Mar 1 '07 #10
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Aug 26 '09 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael A. Covington | last post by:
By default, my PrintPreviewDialog is coming out too small. What is the best way to control its size and position? Ideally, I'd just like to maximize it. Thanks!
0
by: Harry J. Smith | last post by:
I am using the PrintPreviewDialog Window Form from the Toolbox. It displays my RichTextBox contents correctly, but when I click on the Print icon on this form it prints one blank page and no text....
4
by: Steph. | last post by:
Hi, Is there a BUG in the printdialog ? When I create a PrintDialog ans set the "DefaultPageSettings.Landscape" property to "false" and then display the dialog, select "Landscape" and click OK,...
1
by: Blaine | last post by:
When I show my Windows Form as a dialog box (ShowDialog(Me)) and click on a button that calls the ShowDialog of either the PageSetupDialog or PrintDialog conrtol, my Windows Form closes After I...
1
by: Franlin W | last post by:
Is it possible to print directly to file without PrintDialog or PrintPreviewDialog? Have any succeeded to program this feature? Cheers,
2
by: Richard MSL | last post by:
I am using PrintPreviewDialog to preview a file. There is a button that the user can press, which seems to print the file to the default printer. I would like to capture a click on that button so...
3
Spitaki
by: Spitaki | last post by:
Hi, When I call the sub Print the PrintDialog opens twice. What do I have to change so this won't happen again? When I call the sub PrintPreview it works just fine. Has anyone an idea what I do...
0
by: sunny123 | last post by:
How Can i set the print icon in the printpreviewdialog to go to the printdialog? when I click on Report button in my application it'll open the report in print preview screen. There when I click...
2
by: Artie | last post by:
Hi, I've searched the web but can't find a solution to an apparently really simple problem. My app contains an HTML string and I need to be able to invoke the Print Dialog to print the HTML...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.