Profile Picture

add a NDiagramButtonCommand to NDiagramCommandBarsManager menu

Posted By Wilhelm Vortisch 13 Years Ago

add a NDiagramButtonCommand to NDiagramCommandBarsManager menu

Author
Message
Wilhelm Vortisch
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
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

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
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.

Best Regards,
Nevron Support Team



Wilhelm Vortisch
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)Junior Member (14 reputation)

Group: Forum Members
Last Active: 13 Years Ago
Posts: 14, Visits: 1
Hi Nevron Support,

thank you, the above tip has solved my problem.

Regards

Wilhelm



Similar Topics


Reading This Topic