473,795 Members | 3,024 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 15336

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
14452
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
1597
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
5389
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
2618
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
2248
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
9876
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
1851
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
1220
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
7600
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
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
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
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
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...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
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
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.