Reputation: 181
I am working on a project to bring the Google Maps JavaScript API V3 to WPF by displaying a HTML page containing the map control and all JavaScript functions in a WebBrowser control in WPF. I then use InvokeScript on the WebBrowser to run the JavaScript functions I wrote so I can essentially control the map from C# using the JavaScript as a bridge between the two.
This is not a problem as such but a requirement. I do not want the user to have any control of the WebBrowser at all except the map on the page. So how can I eliminate all controls on it? Everything from every ContextMenu on the page and any text to the F5 refresh shortcut to the popups that appear asking to enable features or ActiveX needs to be removed or at least surpressed so they don't do anything and I end up with a control that just renders its HTML source with the user having no control over anything but what is on the page (the map). How can I do this if it is possible, thanks.
Upvotes: 1
Views: 1219
Reputation: 99
using mshtml;
private mshtml.HTMLDocumentEvents2_Event documentEvents;
in constructor or xaml set your LoadComplete event:
webBrowser.LoadCompleted += webBrowser_LoadCompleted;
then in that method create your new webbrowser document object and view the available properties and create new events as follows:
private void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
documentEvents = (HTMLDocumentEvents2_Event)webBrowserChat.Document; // this will access the events properties as needed
documentEvents.oncontextmenu += webBrowserChat_ContextMenuOpening;
}
private bool webBrowserChat_ContextMenuOpening(IHTMLEventObj pEvtObj)
{
return false; // ContextMenu wont open
// return true; ContextMenu will open
// Here you can create your custom contextmenu or whatever you want
}
Upvotes: 0
Reputation: 401
@HenryHunt, Do you mean disable Context menu (right click option)? Then set the IsWebBrowserContextMenuEnabled' to 'False
in the Properties window.
Upvotes: 0