Zenilogix
Zenilogix

Reputation: 1403

Setting initial state of PrintPreviewDialog controls

I'm working with PrintPreviewDialog and want to tweak its initial presentation from the default. So far, I've done this:

            PrintPreviewDialog dlg = new PrintPreviewDialog();
            dlg.WindowState = FormWindowState.Maximized;
            dlg.PrintPreviewControl.Zoom = 1.0;

...which gives me the presentation I want, but when the dialog is opened, the zoom control has the "Auto" choice selected, not 100% as would correspond to the zoom value of 1.0. How can I get at the zoom control to show 100% as the currently selected zoom setting so as not to confuse the user?

BTW, this is VS 2010 .NET 4

Upvotes: 0

Views: 5280

Answers (2)

Hamza el bouti
Hamza el bouti

Reputation: 1

dlg.PrintPreviewControl.Zoom=100/100f;

dlg.PrintPreviewControl.Zoom=2; // 200% Zoom

Upvotes: 1

King King
King King

Reputation: 63377

Maybe setting AutoZoom = false will help:

dlg.PrintPreviewControl.AutoZoom = false;

The PrintPreviewControl should reflect the value of AutoZoom and Zoom but it doesn't. That's a strange thing in its design. However after a search on this control, I've found that we can access to the ToolStrip of the PrintPreviewDialog. This dialog has 2 child controls by default. The first is the PrintPreviewControl which is exposed via the property PrintPreviewControl, the second is the ToolStrip. By looping through the Items, you can find the exact ToolStripSplitButton (the Zoom button) and by looping through the DropDownItems of that splitbutton, we can find the exact 100% toolstripdropdownitem and call PerformClick to check it. However by default, I think we know the index of the item beforehand and the following code would work:

ToolStripSplitButton zoomButton = ((ToolStrip)dlg.Controls[1]).Items[1] as ToolStripSplitButton;
zoomButton.DropDownItems[4].PerformClick();//Check the 100% item in the zoom list

Upvotes: 3

Related Questions