473,739 Members | 9,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access to a printDialog from a PrintPreviewDia log

Hello,

Is there a way to call a printDialog from a printPreviewDia log (from print
icon for example)?
Indeed, the print icon in the printpreviewdia log 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 15318

choupi wrote:
Hello,

Is there a way to call a printDialog from a printPreviewDia log (from print
icon for example)?
Indeed, the print icon in the printpreviewdia log 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
OnPrintButtonCl ick, 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
PrintButtonEnab led property or something like that.

PrintPreviewDia log 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*******@cana da.coma écrit dans le message de news:
11************* ********@h54g20 00...legro ups.com...
>
choupi wrote:
>Hello,

Is there a way to call a printDialog from a printPreviewDia log (from
print
icon for example)?
Indeed, the print icon in the printpreviewdia log 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
OnPrintButtonCl ick, 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
PrintButtonEnab led property or something like that.

PrintPreviewDia log 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.comw rote in message
news:%2******** ********@TK2MSF TNGP05.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.comw rote in message
news:uW******** ******@TK2MSFTN GP02.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 printPreviewDia log (from print
icon for example)?
Indeed, the print icon in the printpreviewdia log 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 PrintPreviewDia log. 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

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

Similar topics

2
14415
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
1595
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. How can I fix this to print the text that is being displayed? Here is the code I use to bring up the form: string stringText = helpTextOut.Text;
4
5385
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, the value of the "DefaultPageSettings.Landscape" is still false !!?? Code Exemple : PrintDialog PDialog = new PrintDialog(); PDialog.PrinterSettings = new System.Drawing.Printing.PrinterSettings();...
1
2617
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 close the PageSetupDialog or PrintDialog. This doesn't happen if the Windows Form is displayed using the Show method. Does anyone have a solution? I've made my own Print Setup Dialog Box (frmPrint). I've added the PrintDocument, PageSetupDialog...
1
2245
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
9873
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 that I can present a PrintDialog, print some files in a special way, etc. But there does not seem to be an event among the PrintPreviewDialog members to do this? Or perhaps I missed it? I would appreciate any suggestions. Thanks.
3
1847
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 wrong? Thanks in advance for your help. Public Sub Print() Try Dim dlgPrint As New PrintDialog()
0
1218
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 the print icon it will directly send the report to the printer. Before report send to the printer i want to give the option for selecting printer by showing print dialog. This is very urgent please help me. Thanks in advance
2
7599
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 correctly formatted (i.e. not as raw HTML) to a printer that the User chooses. So, I need something like:
0
8792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.