您可以使用该WebBrowser控件执行此操作.它将允许您在您的内部显示HTML WinForms.
DocumentText proprety允许您设置表示要显示的HTML的String.
例如:
webBrowser.DocumentText = "<html><body><p>I like StackOverflow</p><body></html>";
Run Code Online (Sandbox Code Playgroud)
之后如果要打印页面,则必须等到文档完成后再调用该Print方法WebBrowser.MSDN显示了一种简单的方法:
private void PrintHelpPage()
{
// Create a WebBrowser instance.
WebBrowser webBrowserForPrinting = new WebBrowser();
// Add an event handler that prints the document after it loads.
webBrowserForPrinting.DocumentCompleted +=
new WebBrowserDocumentCompletedEventHandler(PrintDocument);
// Set the Url property to load the document.
webBrowserForPrinting.Url = new Uri(@"\\myshare\help.html");
}
private void PrintDocument(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).Print();
// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}
Run Code Online (Sandbox Code Playgroud)
您还应该考虑尝试使用该方法PrintDialog来确保问题不是您的打印配置.
以下是MSDN的链接: 在MSDN上使用WebBrowser控件进行打印
可能重复: 打印WebBrowser控件内容