Hi,
how do you programtically click a button on a Toolbar ?
Thanks
Michael
You can add ToolButton->SharedProps->Shortcut (eg: F8) then, in the code:
SendKeys.Send("{F8}");
I solved this in this way:
var button = toolbar.Tools.GetItem(2); //Find the tool ((Infragistics.Win.UltraWinToolbars.ButtonTool)(button )).Checked = true;
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