views:

303

answers:

1

I have a WPF application which contains a WebBrowser control.

Currently, the user can select something within the WebBrowser and can copy the content by dragging it out to another application and dropping it there.

I'd like to be able to stop the user doing this. I'd assumed that there would be a "DragStart" event that I could capture and cancel - but I haven't been able to find something so simple.

Is it possible to capture the start of drag event and cancel it?
Is there a better way to achieve this?

+1  A: 

You can implement IDocHostUIHandler::FilterDataObject and filter out common clipboard formats

You don't get access the WPF browser's native interface until the document is ready. Not sure if it would work with the WPF browser class. There is also a bug in Windows Forms to prevent you from customizing its implementation of IDocHostUIHandler.

You can try some wrapper class of the webbrowser ActiveX, such as the one described at http://www.codeproject.com/KB/miscctrl/csEXWB.aspx

Sheng Jiang 蒋晟
Sorry for not replying sooner - priorities changed and I forgot about this... I have got a fairly empty implementation of the IDocHostUIHandler interface working on my WPF WebBrowser - I've implemented the ShowContextMenu() function. However, I'm not sure how to implement FilterDataObject() - my attempts aren't working and are being ignored. Can you provide more detail?
Grhm
check http://blog.csdn.net/jiangsheng/archive/2004/03/20/3800.aspx. it in MFC, though. Not sure how to implement it in managed code. Maybe you can write a native C++ function and call it via p-invoke?
Sheng Jiang 蒋晟
I've managed to get this working by ensuring IDocHostUIHandler::GetDropTarget returns null. Then FilterDataObject() doesn't appear to be called and dragging is disabled.
Grhm