Windows Develop Bookmark and Share   
 index > Windows Forms General > Menu Command Service
 

Menu Command Service

Hi,

I have created my MenuCommandService class like the code below but how do I show a context menu on a control?

Code Snippet

internal class MenuCommandService : IMenuCommandService

{

ArrayList menuCommands = null;

public MenuCommandService()

{

menuCommands = new ArrayList();

}

public void AddCommand(System.ComponentModel.Design.MenuCommand command)

{

menuCommands.Add(command);

}

public void AddVerb(System.ComponentModel.Design.DesignerVerb verb)

{

}

public System.ComponentModel.Design.MenuCommand FindCommand(System.ComponentModel.Design.CommandID commandID)

{

return null;

}

public bool GlobalInvoke(System.ComponentModel.Design.CommandID commandID)

{

foreach(MenuCommand command in menuCommands)

{

if (command.CommandID == commandID)

{

command.Invoke();

break;

}

}

return false;

}

public void RemoveCommand(System.ComponentModel.Design.MenuCommand command)

{

menuCommands.Remove(command);

}

public void RemoveVerb(System.ComponentModel.Design.DesignerVerb verb)

{

}

public void ShowContextMenu(System.ComponentModel.Design.CommandID menuID, int x, int y)

{

}

public System.ComponentModel.Design.DesignerVerbCollection Verbs

{

get

{

return new DesignerVerbCollection();

}

}

}

Thanks

Loftty

loftty  Wednesday, March 12, 2008 2:17 PM

Hi, Loftty

To add context menu itemsto the right-click short-cut menu at design-time, you should add designer verbs to the designer, you cancheck this document for a sample:

Designer Verbs Class.

Best Regards,
Zhi-xin Ye

Zhi-Xin Ye  Monday, March 17, 2008 5:03 PM
set Control.ContextMenu property?
H. _冬_ Tony  Wednesday, March 12, 2008 2:39 PM

I have tried that but because I useIDesignerHost to host controls the context menu does not seem to work?

Thanks

Loftty

loftty  Wednesday, March 12, 2008 2:42 PM
sorry, I am not familiar with IDesignerHost. even when the control ContextMenu is set, it's not responding to mouse right click? have you checked the control.ContextMenu property in debug mode? is it reset by the 'IDesignerHost'? maybe you can try to hook up the mouse right click event and show the contextmenu yourself?

loftty wrote:

I have tried that but because I useIDesignerHost to host controls the context menu does not seem to work?

Thanks

Loftty

H. _冬_ Tony  Wednesday, March 12, 2008 4:23 PM

Hi, Loftty

To add context menu itemsto the right-click short-cut menu at design-time, you should add designer verbs to the designer, you cancheck this document for a sample:

Designer Verbs Class.

Best Regards,
Zhi-xin Ye

Zhi-Xin Ye  Monday, March 17, 2008 5:03 PM

You can use google to search for other answers

Custom Search

More Threads

• Very noobish question... how can i show a new dialog (header file)
• Detect whether Systray is running or not
• Forms Pass Event
• Add Textbox,Dropdown in Gridview
• Saving stateof a Class that is extending Control Class
• Hide form on startup! / Disable the Close Button
• Resizing
• datetime
• making combobox read only
• Window Resize