문제

나는 .NET에서 인쇄에 완전히 익숙하지 않습니다. 웹 브라우저 컨트롤에 표시된 페이지를 인쇄하고 싶습니다. 어떻게해야하나요?

도움이 되었습니까?

해결책

MSDN은 이에 대한 기사를 가지고 있지만 코드 예제는 웹 브라우저 컨트롤을 사용하여 웹 페이지를 표시하지 않고 인쇄하는 방법을 보여줍니다. :

방법 : 웹 브라우저 컨트롤로 인쇄하십시오

C# 코드 :

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();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top