WebBrowser.Print
-
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(); } }
-
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(); } }
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|