WebBrowser..ShowPrintPreviewDialog();
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 <html></html> even if the string that is being assigned to wbMailBody1.DocumentText is 4 or 5 pages in length.
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();
}
}