Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Handle WebBrowser.ShowPrintDialog() close event without "SHDocVw"

Bharat LeelBharat Leel Member Posts: 3
in C#

To print document I have created separate WindowsApplication and each time I want to print any document I call that application with path as parameter and Print application have below code:

public static void Print(string path)
    WebBrowser wb = new WebBrowser();
    wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);

public static void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    WebBrowser wb = (WebBrowser)sender;
    if (wb.ReadyState.Equals(WebBrowserReadyState.Complete))
        ((SHDocVw.WebBrowser)wb.ActiveXInstance).PrintTemplateTeardown += Print_PrintTemplateTeardown;

void Print_PrintTemplateTeardown(object pDisp)

When I call Print aaplication, using "WebBrowser" control it loads document and show Print Dialog using "wb.ShowPrintDialog();".
On Print Dialog when I click Print or Cancel I got PrintTemplateTeardown event where I asks Application to Exit (To close application).

Now I want to remove "SHDocVw" dependency from my Print Application due to some security issue while installing on client's machine through Internet.

If I remove "SHDocVw", is there any alternate event or solution available that achknowledge me that PrintDialog is closed?


  • Bharat LeelBharat Leel Member Posts: 3

    In sample I have put two button, first button has written above montioned code.

    Due to SHDocVw we can convert WebBrowser.ActiveXInstance object to SHDocVw.WebBrowser which provides us PrintTemplateTeardown callback event which will notify us if user will either click on Print or Cancel button (ultimately ShowPrintDialog() close event).

    Now due to some requirement I want to remove dependency of SHDocVw from my project, so looking for alternate of SHDocVw which will provide me ShowPrintDialog()'s close event.

    You can download and try this -->

  • Himanshu MishraHimanshu Mishra Member Posts: 11

    Hey guys if you are getting bored in your free time then here on our homepage on just single click here qwertyui you will play many free online trending games and videos here on our homepage.

Sign In or Register to comment.