I'm using a WebBrowser control in .NET CF 3.5 for a Windows CE device application, and for security reasons need to disable the Context Menu. I've tried a variety of things, none of which seem to work for mobile devices with .NET CF 3.5:
I've tried placing a pictureBox over the WebBrowser, and setting it to be transparent. Unfortunately, the transparency doesn't work and this ends up being a white box over my browser.
I've tried implementing a new custom transparent control to place over the web browser, similar to this .
I've tried editing the OnContextMenu element in the html, no luck.
I've tried overriding the CreateParams to make a transparent PictureBox over the browser, noted as one of the solutions here .
There seems to be many solutions for this online, but none of them seem to work for windows CE with .NET CF 3.5. I believe this is because the WebBrowser has a much simpler implementation than the full .NET 3.5. So my question is thus: is there any way to disable the context menu for the WebBrowser control?
I've not tried it for this specific control, so I don't know if it will work, but have you tried subclassing the browser control and intercepting and discarding the messages that cause the context menu to appear in the first place? That's certainly what I'd try first if I had to solve the same problem.
It's actually not that hard to use the native HTML Control API (not IWebBrowser2 et al) by P/Invoking it from C#, if you feel that you're not enough in charge of the managed WebBrowser.
If you go that way, then you can either
or
Been there, done that, both works.
Edit:
There are 3 possible levels of complexity in this case:
None of these possible answers work. So I gave up trying to hide the context menu and just added an event handler for the Navigating event and cancel the navigation if it's not the same URL as the one I originally sent it to. It still shows the context menu but clicking on anything will not send it to another page
void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
//don't let users go anywhere else
if (e.Url != webBrowser1.Url) {
e.Cancel = true;
}
}
.NET CF中的WebBrowser控件实现不包含属性IsWebBrowserContextMenuEnabled
吗?
I just came across this very interesting blog entry while looking for other stuff. I sure looks like it solves the context menu issue (caveat: I'm not tested this at all).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.