Results 1 to 4 of 4

Thread: [Resolved][2.0]Force print in web browser control

  1. #1

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    [Resolved][2.0]Force print in web browser control

    I have a file in html that I need to open and print.

    It doesn't print and it doesn't show the print dialog.

    Is the problem likely to be related to the fact that I never
    actually display the browser control on the screen?
    I kinda want this to be done behind the scenes.

    It gets the path and converts it correctly, (i.e. c://thisfolder becomes c:/thisfolder like it should)


    Code:
    public void PrintFile()
            {
                //Create a new IE control
                System.Windows.Forms.WebBrowser myBrowser = new System.Windows.Forms.WebBrowser();
                //Load it with file
                Uri myURL = new Uri(GetDefaultPath() + "PrintThisFile.html");
                myBrowser.Navigate(myURL);
                myBrowser.Refresh();
    
                //Print it
                myBrowser.ShowPrintPreviewDialog();
                myBrowser.Print();
                //close and clean up
                myBrowser.Dispose();
    
            }//PrintFile()
    Last edited by JPicasso; Aug 1st, 2006 at 07:02 AM.
    Merry Christmas

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Force print in web browser control

    Try the same thing but add the control to the form's Controls collection. If it works then you know that's the issue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Re: Force print in web browser control

    Hmmm.

    It's not a form. Its a separate class.

    Maybe I need a form.
    Merry Christmas

  4. #4

    Thread Starter
    Fanatic Member JPicasso's Avatar
    Join Date
    Aug 2001
    Location
    Kalamazoo, MI
    Posts
    843

    Re: Force print in web browser control

    DOH!

    Apparently, one has to wait for the document to load before trying to print it.

    So after I .Navigate, I put in a catch for the myBrowser.DocumentCompleted.
    I print and dispose in the handler.
    Merry Christmas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width