Hi,
how do you programtically click a button on a Toolbar ?
Thanks
Michael
I have changed you code slightly to create and add the root tool and then add an instance of that tool to the first toolbar in the toolbars manager:
Infragistics.Win.UltraWinToolbars.ButtonTool btnCheckRootTool = new Infragistics.Win.UltraWinToolbars.ButtonTool("Press"); this.ultraToolbarsManager1.Tools.Add(btnCheckRootTool);
Infragistics.Win.UltraWinToolbars.ButtonTool btnCheckInstanceTool = (Infragistics.Win.UltraWinToolbars.ButtonTool)this.ultraToolbarsManager1.Toolbars[0].Tools.AddTool("Press");btnCheckInstanceTool.ToolClick+=new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(btnCheck_ToolClick);
private void btnCheckInstanceTool_ToolClick(object sender, ToolClickEventArgs e) {
}
You can try that, but I believe the event will only be fired if that specific instance of the tool is clicked. Also, if you are programmatically adding the tool to a toolbar, menu, or ribbon group after EndInit() has been called on the toolbars manager in the designer code, the tools will be cloned anyway, so you would be hooking the event on a tool that wasn't actually added. After the toolbars manager is initialized, you should call Tools.AddTool() and pass in the key of the tool you want to add. Get the return value and hook any events on that tool, which is the tool that was actually added to the container.
You can do something like this:
protected override void OnLoad(EventArgs e){ ... // add a listner for the ToolClick event ToolbarManagerName.ToolClick += OnToolbarManagerToolClick; ... } private void OnToolbarManagerToolClick(object sender, ToolClickEventArgs e){ switch (e.Tool.Key) { case "ToolKey1": DoToolKey1Action(); } } private void DoToolKey1Action(){ // specific code to complete the selected operation }
Now to simulate a click on the ToolKey1 tool button you just call the DoToolKey1Action from your code.
HTH,
Emanuel