如何在Forms.WebBrowser中覆盖print

时间:2013-03-27 02:00:34

标签: c# printing webbrowser-control

System.Windows.Forms中的WebBrowser类不能正确处理DrawtoBitmap方法,如msdn所述。

我希望覆盖OnPrint方法并执行我自己的绘图代码。

我已尝试覆盖WebBrowser类中的OnPrint(PrintEventArgs e)方法并调用代码,但打印不会更改。

我还尝试捕获WM_PRINT方法(0x317),然后从消息句柄创建自己的Graphics。我尝试过使用BeginPaintSelectObjectEndPaint等NativeMethods。再次调用代码,但打印不会改变。

1 个答案:

答案 0 :(得分:2)

覆盖WndProc(ref Message m)方法。

if (m.Msg == 0x317 || m.Msg == 0x318) //WM_PRINT, WM_PRINTCLIENT
{
    using (Graphics g = Graphics.FromHdc(m.WParam))
    {
        //Draw here
    }
}