问题
Currently I am using an application which play ppt
and flash in WebBrowser Control.
In WebBrowser I am able to hide context menu by using
this.IsWebBrowserContextMenuEnabled = false;
and capture key event by using
this.PreviewKeyDown += new PreviewKeyDownEventHandler(IWebBrowser_PreviewKeyDown);
but while playing the ppt
, both context menu and keypress events are not functioning i.e. I can see context menu and arrow key force the ppt
to change the slide.
Again while playing flash, context menu is visible and I can handle key event. is there any other setting to it can same for whatever (HTML
, PPT
, Flash
, PDF
) is playing in webBrowser?
Edit :1 Here is my existing code
class IWebBrowser : WebBrowser
public IWebBrowser(RegionOptions options)
{
try
{
this.Width = 600;
this.Height = 400;
this.IsWebBrowserContextMenuEnabled = false;
this.ScrollBarsEnabled = false;
this.ScriptErrorsSuppressed = true;
this.WebBrowserShortcutsEnabled = false;
this.AllowNavigation = true;
CreateContextMenu();
this.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(IWebBrowser_DocumentCompleted);
this.PreviewKeyDown += new PreviewKeyDownEventHandler(IWebBrowser_PreviewKeyDown);
}
catch (Exception ex)
{
log.Error("IWebBrowser - ctor ", ex);
}
}
private void CreateContextMenu()
{
ContextMenuStrip myContextMenu = new ContextMenuStrip();
this.ContextMenuStrip = myContextMenu;
ToolStripMenuItem myFirstTooltip = new ToolStripMenuItem();
ToolStripMenuItem mySecondTooltip = new ToolStripMenuItem();
ToolStripMenuItem myThirdTooltip = new ToolStripMenuItem();
myFirstTooltip.Text = "Item One";
mySecondTooltip.Text = "Item Two";
myThirdTooltip.Text = "Item Three";
myContextMenu.Items.Add(myFirstTooltip);
myContextMenu.Items.Add(mySecondTooltip);
myContextMenu.Items.Add(myThirdTooltip);
}
context menu Images for different controls played in webbrowser
Display a webpage..................

flash played in webbrowser.................

ppt played in webbrowser.....................

回答1:
Override all the mouse event flags Here is an example I hope this example will help you
回答2:
Follow these steps to get rid of the default context menu
Do what you've done to hide default context menu
this.IsWebBrowserContextMenuEnabled = false;
Add a
ContextMenuStrip
control to your window and give a name (let's say MyMenu)Set your browser control's ContextMenuStrip property to MyMenu
Now, whatever the document type you display on your Browser control it'll only display your custom menu.
Hope this helped!
All the best
回答3:
You've to catch the PreviewKeyDown event in your WebControl where is playing your ppt/flash and rise it to the content page or whatever.
You can check how: define Custom Event for WebControl in asp.net
来源:https://stackoverflow.com/questions/25884830/handling-key-events-on-webbrowser-control