0

when I tried using print preview from the C # Web Browser, the window was open but the size was small. the final expectation is that the window is maximized

here I attach a snippet:

public void execPrint(String url) {
            System.Windows.Forms.WebBrowser ie = new System.Windows.Forms.WebBrowser();
            ie.DocumentCompleted += Ie_DocumentCompleted;
            ie.Navigate(url);
            ie.Visible = false;
}

private void Ie_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
            System.Windows.Forms.WebBrowser ie = (System.Windows.Forms.WebBrowser)sender;           
            ie.ShowPrintPreviewDialog();
}
Stenly
  • 1
  • 2

2 Answers2

0

Print Preview Dialog box is showing small size as below:

This is because its parent "ie" WebBrowser is has not any parent container.

Just apply WebBrowser to current window form, to make it full screen.

public void execPrint(String url)
{
    System.Windows.Forms.WebBrowser ie = new System.Windows.Forms.WebBrowser();
    this.Controls.Add(ie);
    ie.ScriptErrorsSuppressed = true;
    ie.DocumentCompleted += Ie_DocumentCompleted;
    ie.Navigate(url);
    ie.Visible = false;
}

private void Ie_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
    System.Windows.Forms.WebBrowser ie = (System.Windows.Forms.WebBrowser)sender;
    ie.ShowPrintPreviewDialog();

}

You can see that i have entered only one line this.Controls.Add(ie); and its now showing maximized window for Preview Dialog.

Check this:

I hope it will helpful to you.

Thanks

saAction
  • 2,035
  • 1
  • 13
  • 18
  • Apologize since I'm not clear in stating that this is for ActiveX, not Windows Application, hence, this.Controls is not available. Could you advise similar way in ActiveX? Thank you very much. – Stenly Aug 20 '18 at 07:26
0

To solve this problem, resize the form that includes the web browser. The web browser print preview size is same as parent form. For example, if you want full screen print preview:

this.Winsowstate = System.Windows.Forms.FormWindowState.Maximaized;

webbrowser1.ShowPrintPreviewDialog();

this.Windowstate = System.Windows.Forms.FormWindowState.Normal;