System.Windows.Forms中的WebBrowser类不能正确处理DrawtoBitmap
方法,如msdn所述。
我希望覆盖OnPrint
方法并执行我自己的绘图代码。
我已尝试覆盖WebBrowser类中的OnPrint(PrintEventArgs e)
方法并调用代码,但打印不会更改。
我还尝试捕获WM_PRINT
方法(0x317),然后从消息句柄创建自己的Graphics。我尝试过使用BeginPaint
,SelectObject
和EndPaint
等NativeMethods。再次调用代码,但打印不会改变。
答案 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
}
}