Context menu for nonform application  
Author Message
MaGeorge





PostPosted: Visual C# General, Context menu for nonform application Top

How can I have context menu in an applicationb where I don't have any form What about the localization of context menu

Visual C#14  
 
 
Mike Danes





PostPosted: Visual C# General, Context menu for nonform application Top

If you don't have any form then where the context menu shows up !

As for localization you can do the following if you use ContextMenuStrip and not ContextMenu.

1) create a class derived from ContextMenuStrip

2) open the designer for this class (it's a component so it has a component designer)

3) now you can go to properties and set the Items in much the same way as you do in a form


 
 
Udhaya Kumar D





PostPosted: Visual C# General, Context menu for nonform application Top

try this one..............

private void UserControl_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
contextMenu1.Show(this,new Point(e.X,e.Y));
}
}

 
 
MaGeorge





PostPosted: Visual C# General, Context menu for nonform application Top

Is this the only way to localize the context menu by deriving from ContextMenuStrip Is this the remonded way to solve this problem
 
 
Mike Danes





PostPosted: Visual C# General, Context menu for nonform application Top

No, it's not the only solution, it's just the most strightforward one (in my opinion). Other 2 possible solutions:

1) Add a component to your project and using the designer view of the component add a ContextMenuStrip to it. Localize it like you would do when the context menu is in a form/user control and after that add a public property to expose the context menu to other code. You can add additional context menus and properties if you need more than one.

2) You can do it manually by adding the strings that you need in the context menu to the project Resources file and then creating the menu manually using this strings, something like this:

ContextMenuStrip menu = new ContextMenuStrip();

menu.Items.Add(new ToolStripMenuItem(global::ProjectName.Properties.Resources.MenuItem1Text));

menu.Items.Add(new ToolStripMenuItem(global::ProjectName.Properties.Resources.MenuItem2Text));

etc.

As for recomended solution, I don't know. Any of these work. In some cases you may need a menu those items are dynamically generated at runtime so 2) is the only option in that case.