Handling key events on WebBrowser control?

风流意气都作罢 提交于 2019-12-10 19:54:23

问题


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

  1. Do what you've done to hide default context menu

    this.IsWebBrowserContextMenuEnabled = false;

  2. Add a ContextMenuStrip control to your window and give a name (let's say MyMenu)

  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!