all groups > c# > november 2006 >
You're in the

c#

group:

Access to a printDialog from a PrintPreviewDialog


Re: Access to a printDialog from a PrintPreviewDialog Bruce Wood
11/30/2006 3:24:20 PM
c#:

[quoted text, click to view]

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.
Access to a printDialog from a PrintPreviewDialog choupi
11/30/2006 9:54:11 PM
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.

Re: Access to a printDialog from a PrintPreviewDialog choupi
12/1/2006 12:00:00 AM
Ok, so there's no way to add a new button in the toolbar I imagine ?!

"Bruce Wood" <brucewood@canada.com> a écrit dans le message de news:
1164929060.669327.63600@h54g2000cwb.googlegroups.com...
[quoted text, click to view]

Re: Access to a printDialog from a PrintPreviewDialog choupi
12/1/2006 12:00:00 AM
Well, I just have found a simple way using Reflection, and it works
perfectly.
Let me know if you're interested.

Thanks.

Re: Access to a printDialog from a PrintPreviewDialog RobinS
12/1/2006 9:36:42 AM
We're interested!
Robin S.
---------------------------------
[quoted text, click to view]

Re: Access to a printDialog from a PrintPreviewDialog RobinS
12/5/2006 10:46:33 AM
Thanks!
Robin S.
[quoted text, click to view]

Re: Access to a printDialog from a PrintPreviewDialog choupi
12/5/2006 4:48:27 PM
using System;

using System.Reflection;

using System.Drawing;

using System.Drawing.Printing;

using System.Windows.Forms;

namespace Test

{

public class MyPrintPreviewDialog : System.Windows.Forms.PrintPreviewDialog

{

private ToolBarButton myPrintButton;

public MyPrintPreviewDialog() : base()

{

Type t = typeof(PrintPreviewDialog);

FieldInfo fi = t.GetField("toolBar1", BindingFlags.Instance |
BindingFlags.NonPublic);

FieldInfo fi2 = t.GetField("printButton", BindingFlags.Instance |
BindingFlags.NonPublic);

ToolBar toolBar1 = (ToolBar)fi.GetValue(this);

ToolBarButton printButton = (ToolBarButton)fi2.GetValue(this);


printButton.Visible = false;


myPrintButton = new ToolBarButton();

myPrintButton.ToolTipText = printButton.ToolTipText;

myPrintButton.ImageIndex = 0;


ToolBarButton[] oldButtons = new ToolBarButton[toolBar1.Buttons.Count-1];

for(int i = 0 ; i < oldButtons.Length ; i++) oldButtons[i] =
toolBar1.Buttons[i+1];


toolBar1.Buttons.Clear();

toolBar1.Buttons.Add(myPrintButton);

for(int i = 0 ; i < oldButtons.Length ; i++)
toolBar1.Buttons.Add(oldButtons[i]);

toolBar1.ButtonClick += new ToolBarButtonClickEventHandler(toolBar1_Click);

}

private void toolBar1_Click(object sender, ToolBarButtonClickEventArgs
eventargs)

{

if (eventargs.Button == myPrintButton)

{

PrintDialog printDialog1 = new PrintDialog();

printDialog1.Document = this.Document;

if (printDialog1.ShowDialog() == DialogResult.OK) this.Document.Print();

}

}

}

}

Re: Access to a printDialog from a PrintPreviewDialog Duggi
12/6/2006 12:07:53 AM
thats quite interesting!!!

Thanks
-Srinivas.

[quoted text, click to view]
Re: Access to a printDialog from a PrintPreviewDialog davidjt52
1/14/2007 5:55:15 PM
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:

public class MyPrintPreviewDialog :
System.Windows.Forms.PrintPreviewDialog
{
private ToolStripButton myPrintButton;
public MyPrintPreviewDialog ( ) : base ( )
{
Type t = typeof ( PrintPreviewDialog );
FieldInfo fi = t.GetField ( "toolStrip1",
BindingFlags.Instance | BindingFlags.NonPublic );
FieldInfo fi2 = t.GetField ( "printToolStripButton",
BindingFlags.Instance | BindingFlags.NonPublic );
ToolStrip toolStrip1 =
( ToolStrip ) fi.GetValue ( this );
ToolStripButton printButton =
( ToolStripButton ) fi2.GetValue ( this );
printButton.Visible = false;
myPrintButton = new ToolStripButton ( );
myPrintButton.ToolTipText = printButton.ToolTipText;
myPrintButton.ImageIndex = 0;

ToolStripItem [ ] oldButtons =
new ToolStripItem [ toolStrip1.Items.Count ];
for ( int i = 0; i < oldButtons.Length; i++ )
oldButtons [ i ] = toolStrip1.Items [ i ];

toolStrip1.Items.Clear ( );
toolStrip1.Items.Add ( myPrintButton );
for ( int i = 0; i < oldButtons.Length; i++ )
toolStrip1.Items.Add ( oldButtons [ i ] );
toolStrip1.ItemClicked +=
new ToolStripItemClickedEventHandler ( toolBar1_Click );
}

private void toolBar1_Click ( object sender,
ToolStripItemClickedEventArgs eventargs )
{
if ( eventargs.ClickedItem == myPrintButton )
{
PrintDialog printDialog1 = new PrintDialog ( );
printDialog1.Document = this.Document;
if ( printDialog1.ShowDialog ( ) == DialogResult.OK )
this.Document.Print ( );
}
}
}


Thanks again for your inspiration.
Re: Access to a printDialog from a PrintPreviewDialog yannick.devisscher NO[at]SPAM gmail.com
3/1/2007 10:05:13 AM
Thx!! this was very useful !
AddThis Social Bookmark Button