Hi,
how do you programtically click a button on a Toolbar ?
Thanks
Michael
I think the best thing to do here would be to separate out the click event handler code for this one tool into its own method which is called from the normal ToolClick event handler. Then you can call that method from anywhere else in your code and simulate the button's click action without having to interact with the toolbars manager.
Hi Mike,
suppose to have a toolbar that composes itself at runtime and a specific place could be occupied by two (or more) different ButtonTools. In this case you can not know what code to execute, it depends on what ButtonTool has been used. So, please could you demonstrate me how to invoke the click programmatically?
Thanks in advance Gianni
I have the same problem
If tlbPulsanti.Tools.Exists(sTool) Then tlbTool = tlbPulsanti.Tools(sTool) If tlbTool.EnabledResolved Then If tlbTool.GetType Is GetType(ButtonTool) Then DirectCast(tlbTool , ButtonTool) ..... Click
I dont'know sTool value but i must invoke the click programmatically.In UltraGrid there is PerformAction(UltraGridAction)
Lorenzo
Have you tried what was described at the top of the thread (creating a method to handle the button click logic and call it both from the UltraToolbarsManager.ToolClick event handler and the place where you need to invoke the click programmatically)? That is the best way to implement this.
You can add ToolButton->SharedProps->Shortcut (eg: F8) then, in the code:
SendKeys.Send("{F8}");
What I can understand from your code is that from one part of your code you need to activate a functionality that you don't have access to.
Instead of clicking a ButtonTool, I think you should make that functionality public, so you can invoke it from other libraries.
For me, having to mimic a click on a UI control to invoke something looks like a bad design.
Emanuel
PS: Here is the initial code I posted in this thread, modified for the situation I described above:
Library 1:
The class (Class1) where you are adding the button tool to toolbar:
private void OnToolbarManagerToolClick(object sender, ToolClickEventArgs e){ switch (e.Tool.Key) { case "ToolKey1": Class2.Action1(); } }
The class (Class2) that contains the functionality you seek:public void Action1(){ // specific code to complete the selected operation }
From you main application, when you need to invoke the same functionality as the click on the button tool:
...
Class2.Action1();
In the code above I've used Class2 and should be treated as an instance call or as a static call, depending on your situation.
Currently there is no way to programmatically click a tool. You can submit a feature request for this.
It isn't possible. The button tools are dinamically created in a dll from a configuration file. Each user chooses the menu to emulate from button.
I solved in this (terrible) way:
tlbTool = Me.Tools(sTool)With DirectCast(tlbTool, ButtonTool) Dim aAppearanceData As Infragistics.Win.AppearanceData = Nothing With .SharedProps.ToolInstances(0) .ResolveAppearance(aAppearanceData, Infragistics.Win.AppearancePropFlags.BackColor) Dim srt As Shortcut = .SharedProps.Shortcut .SharedProps.Shortcut = Shortcut.Ctrl0 SendKeys.Send("^0") Application.DoEvents() .SharedProps.Shortcut = srt .SharedProps.AppearancesSmall.AppearanceOnMenu.BackColor = aAppearanceData.BackColor End With aAppearanceData = Nothing End With