Nevron Forum

add a NDiagramButtonCommand to NDiagramCommandBarsManager menu

https://www.nevron.com/Forum/Topic4732.aspx

By Wilhelm Vortisch - Thursday, January 13, 2011

Hi *,

I try to add a custom toolbar command

public class NCustomDiagramButtonCommand : NDiagramButtonCommand
{
// [...]

public NCustomDiagramButtonCommand()
: base((int)DiagramCommandRange.Misc, (int)DiagramCommand.LastCommandId + 1, "Custom command", "Custom button command in a custom toolbar.")
{
}

public override void Execute()
{
MessageBox.Show("NCustomDiagramButtonCommand was executed.");
}
// [...]
}

with

// create the custom buttom command if not already craated
if (customDiagramButtonCommand == null)
{
customDiagramButtonCommand = new NCustomDiagramButtonCommand();
Form.CommandBarsManager.Commander.Commands.Add(customDiagramButtonCommand);
}

to one of the menu entrys (the "Edit" menu) in the main menu bar with:

NMenuBar mainMenu = (NMenuBar)Form.CommandBarsManager.Toolbars["Main Menu"];
mainMenu.Commands[2].Commands.Add(NCommand.FromContext((NCommandContext)customDiagramButtonCommand.CreateUICommand()));

If I call this after
Form.CommandBarsManager.Recreate();
the new menu entry is shown, but if I clicked the new menu entry, the "Execute" procedure of the NCustomDiagramButtonCommand object isn't fired.

Why?

Regards

Wilhelm
By Nevron Support - Friday, January 14, 2011

Hi Wilhelm,

You have to create the command that you add to the main menu Commands collection as follows:

int id = customDiagramButtonCommand.Id;
NCommandContext context = Form.CommandBarsManager.Contexts.ContextFromID(id);
NCommand cmd = NCommand.FromContext(context);

I hope this helps.
By Wilhelm Vortisch - Monday, January 17, 2011

Hi Nevron Support,

thank you, the above tip has solved my problem.

Regards

Wilhelm