طباعة المحتوى التحكم WebBrowser
سؤال
وأنا جديدة تماما للطباعة في .NET. أود أن طباعة الصفحة التي يتم عرضها في التحكم WebBrowser. كيف أفعل ذلك؟
المحلول
وMSDN ديه مقالا حول هذا الموضوع، ولكن المثال مدوناتها يوضح كيفية استخدام عنصر التحكم WebBrowser لطباعة صفحة ويب دون عرضه. :
كيفية: طباعة مع التحكم WebBrowser
ووج # رمز:
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();
}
لا تنتمي إلى StackOverflow