Welcome Guest Search | Active Topics | Sign In | Register

Custom menu item to show only when selecting text Options
Khoa
Posted: Thursday, October 2, 2014 5:24:01 PM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
Hi,

I would like to add a new MenuItem on EO.WebBrowser which looks like "Copy" on right click. Whenever user selects a text and does right click, the context menu will display my menu item. Without selecting a text, this menu item will not show up on right click.

Thank you.
eo_support
Posted: Friday, October 3, 2014 12:50:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

You will need to handle the WebView's BeforeContextMenu event and then check e.MenuInfo.SourceFlags. For example, the following code creates a custom context menu and only if the source is a selection, the copy menu item is added into the context menu:

Code: C#
void WebView_BeforeContextMenu(object sender, BeforeContextMenuEventArgs e)
{
    //Clear the default context menu
    e.Menu.Items.Clear();

    //Add other menu items
    ....

    //Only add "Copy" menu item if the source of the context menu is a selection
    if ((e.MenuInfo.SourceFlags & ContextMenuSourceFlags.Selection) != 0)
        e.Menu.Items.Add(new EO.WebBrowser.MenuItem("Copy", CommandIds.Copy));
}


Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!
Khoa
Posted: Friday, October 3, 2014 1:47:18 PM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
The code works great. It is exactly what I am looking for. Thank you!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.