3

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..................
Contextmenu webpage
flash played in webbrowser.................
Context menu in flash(displayed in webbrowser)
ppt played in webbrowser.....................
Context menu in PPT(displayed in webbrowser)

madan
  • 773
  • 13
  • 38

3 Answers3

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

Sam
  • 2,917
  • 1
  • 15
  • 28
1

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

Community
  • 1
  • 1
paio
  • 167
  • 4
  • This answer gave me the clue - you have to catch PreviewKeyDown on the webcontrol. If you are using Form.PreviewKeyDown with KeyPreview = True that won't work, it has to be on the control itself – user2728841 Jan 21 '22 at 17:05
1

Override all the mouse event flags Here is an example I hope this example will help you

Community
  • 1
  • 1