Windowsフォームプロジェクトで新しいWebブラウザーコントロールを作成して、フォーマットされたHTMLを印刷しています。特別にフォーマットされたバージョンのページを印刷しているだけなので、ユーザーはコントロールを表示する必要はありません。
これは私が現在使用している印刷のプロセスです。
internal void PrintQuestion(SessionPart SessionPart)
{
WebBrowser wbForPrinting = new WebBrowser(); //<-- Undisposed local
wbForPrinting.Parent = this;
wbForPrinting.DocumentCompleted += wbForPrinting_DocumentCompleted;
wbForPrinting.DocumentText = string.Format(DOCUMENT_HTML, SessionPart.Session.Course.Product.Name, HtmlFormatter.GetPrintableQuestion(SessionPart));
}
void wbForPrinting_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
// Print the document now that it is fully loaded.
((WebBrowser)sender).ShowPrintPreviewDialog();
}
印刷プレビューの表示ダイアログの直後にWebBrowserを破棄すると、印刷しようとしているオブジェクトが破壊されるため、破棄できません。ユーザーがWebBrowserを使い終わったことを判断するイベントや方法はないようです(印刷を終了するか、プレビューをキャンセルします)。これはこのプロジェクトの最後の部分であり、私の時間は尽きています。私は処分されていない地元の人を残したくありません。