.net 4.0、Visual Studio 2010、およびWindowsフォームを使用してC#で.htmファイルを印刷する良い方法が見つからないようです。直接印刷しようとすると、「ページ」自体を印刷するのではなく、生のhtmlデータを印刷しました。
私がそれを印刷することを知っている唯一の方法は、WebBrowserコントロールを使用することです。ドキュメントを印刷すると、色が印刷されず、ページが正しく印刷されません。たとえば、エッジは描画されません。
Webブラウザのコード:
public void Print()
{
// 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(Core.textLog);
}
private void PrintDocument(object sender, WebBrowserDocumentCompletedEventArgs e)
{
((WebBrowser)sender).ShowPrintDialog();
//// Print the document now that it is fully loaded.
//((WebBrowser)sender).Print();
//// Dispose the WebBrowser now that the task is complete.
((WebBrowser)sender).Dispose();
}
私に何ができる?
ありがとうございました!