views:

552

answers:

4

I have a program where I can switch between different layouts in my print doument (a4, a5 or a6 sized graphics drawings and whatnot. Print document is always a4 sized). I can show this document in a PrintPreviewDialog but I have to manually specify in the code before hand which layout I want to see.

I want a new button added to the PrintPreviewDialog toolbar that lets me simply switch between these different layouts.

Don't worry about the function of the button, I just want to get it up there and connected to whatever method (that I myself will code). Cheers!

A: 

Did you try to create a new class and inherit from PrintPreviewDialog ?

Bryan
+1  A: 

You can always make your own. Add the PrintPreviewControl to your form with any buttons that you want/need. Then set the Document property on the control to be whatever printable object you want.

Edit> It works quite well btw. I have done this, because I added some Microsoft.Ink controls to the form (to allow for signing the the previewed document). Then I just call ppcDocument.RefreshPreview();

SnOrfus
A: 

Me again.

I've seen some 'elaborate' code pieces around the web that take use of PrintPreviewControl. A few hundred lines of code or more.

They also all take use of Form. I don't want that. I know that PrintPreviewDialog takes use of it on some level but I don't want to actually have a Form file or write in a Form body into my code.

Isn't there any speedy way for me to either inherit PrintPreviewDialog or set up a PrintPreviewControl that lets me add a new button without involving a Form body/file?

Wollan
+2  A: 

Well, I think I managed to do it. Here's the inspiration: davidjt52 @ bytes.com

Here's the code I ended up writing (this class is called upon when I want to preview my document elsewhere in the overall program):

using System.Reflection; //FieldInfo

public class MyPrintPreviewDialog : PrintPreviewDialog { private ToolStripButton myTestButton;

public MyPrintPreviewDialog() : base()
{
    Type T = typeof(PrintPreviewDialog);
    FieldInfo fi = T.GetField("toolStrip1", BindingFlags.Instance | 
    BindingFlags.NonPublic);
    ToolStrip toolStrip1 = (ToolStrip)fi.GetValue(this);

    myTestButton = new ToolStripButton();
    myTestButton.ToolTipText = "TEST";
    myTestButton.ImageIndex = 0;
    myTestButton.Click += new EventHandler(Btn_Click);

    Button Btn = new Button();
    toolStrip1.Items.Add(myTestButton);
}

private void Btn_Click(object Sender, EventArgs args)
{
    MessageBox.Show("Button Clicked");
}

}

Thanks for all your help. :)

Correction: I know I managed to do it.

Wollan