Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. WebBrowser.Print

WebBrowser.Print

Scheduled Pinned Locked Moved C#
csharphtml
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TiredProgrammer
    wrote on last edited by
    #1

    We have a program that we are using to 'print' and 'print preview' an html document that is being displayed within a C# program. We open a new webbrowser adding info using html statements and then add the contents of the original webbrowser to our new webbrowser. When we call wbMailBody1.Print(); or wbMailBody1.ShowPrintPreviewDialog(); we get an empty page. If we add the line MessageBox.Show(""); immediately before calling wbMailBody1.Print(); or wbMailBody1.ShowPrintPreviewDialog(); it will work perfectly the following code displays an empty page. if you check wbMailBody1.DocumentText.Length it will be 14 even if it should be the length of say 4 or 5 pages in length. If you look at wbMailBody1.DocumentText it will contain the GetHTML() routine uses stringBuilder to create a string using sb.Append statements. private void PrintMessagePreview1() { GetHeading(); if (viewMode == Dice.BodyViewMode.HTML) { wbMailBody1.DocumentText = GetHTML(); wbMailBody1.ShowPrintPreviewDialog(); } else { printPreviewDialog1.ShowDialog(); } } If you make the following change to the code (MessageBox.Show statement) then all works just the way it should. private void PrintMessagePreview1() { GetHeading(); if (viewMode == Dice.BodyViewMode.HTML) { wbMailBody1.DocumentText = GetHTML(); MessageBox.Show(""); wbMailBody1.ShowPrintPreviewDialog(); } else { printPreviewDialog1.ShowDialog(); } }

    S 1 Reply Last reply
    0
    • T TiredProgrammer

      We have a program that we are using to 'print' and 'print preview' an html document that is being displayed within a C# program. We open a new webbrowser adding info using html statements and then add the contents of the original webbrowser to our new webbrowser. When we call wbMailBody1.Print(); or wbMailBody1.ShowPrintPreviewDialog(); we get an empty page. If we add the line MessageBox.Show(""); immediately before calling wbMailBody1.Print(); or wbMailBody1.ShowPrintPreviewDialog(); it will work perfectly the following code displays an empty page. if you check wbMailBody1.DocumentText.Length it will be 14 even if it should be the length of say 4 or 5 pages in length. If you look at wbMailBody1.DocumentText it will contain the GetHTML() routine uses stringBuilder to create a string using sb.Append statements. private void PrintMessagePreview1() { GetHeading(); if (viewMode == Dice.BodyViewMode.HTML) { wbMailBody1.DocumentText = GetHTML(); wbMailBody1.ShowPrintPreviewDialog(); } else { printPreviewDialog1.ShowDialog(); } } If you make the following change to the code (MessageBox.Show statement) then all works just the way it should. private void PrintMessagePreview1() { GetHeading(); if (viewMode == Dice.BodyViewMode.HTML) { wbMailBody1.DocumentText = GetHTML(); MessageBox.Show(""); wbMailBody1.ShowPrintPreviewDialog(); } else { printPreviewDialog1.ShowDialog(); } }

      S Offline
      S Offline
      Spacix One
      wrote on last edited by
      #2

      this.WebBrowser1.Document.InvokeScript("window.print");


      -Spacix All your skynet questions[^] belong to solved


      I dislike the black-and-white voting system on questions/answers. X|


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups