HI at all,
How can I fire the click event of a tool from the Ultratoolbar manually by code?I read something about a "perform default action" thing somewhere, but can't remember.I thought about one of the following ways:Toolbarsmanager.tools("button").performaction ... or ... eventmanager.event("click").activate()OR OTHERWISE Toolbarsmanager_Toolsclick(me, [set eventargs to buttontool])
But I don't find any way to do this.
On the second way I don't know how to set/create the eventargs manually to raise the toolsclick event properly.
Have anybody a solution for this?
Thanks
Vince McDonald is totally right about the very best practice to design the code to be decouple from the UI controls.
However, if you really want to hack the system to raise the event without having to redesign your application in cases where you don't have the capability to change it, here is a little workaround to do the job:
toolbarsManager.GetType().InvokeMember("FireEvent", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, toolbarsManager, new object[] { ToolbarEventIds.ToolClick, new ToolClickEventArgs(button, null) });
where toolbarsManager is your ToolBar and button is the button you want to trigger the click event.
I have to say that I currently use this hack because the toolbar is filled with a component that inject objects inside each ButtonTool and listen the ToolClick to execute action linked with the objects injected inside ButtonTool and for this reason, I'm not able to grab the Action Executer to change the design.
Vince,
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
Vince McDonald said: It's generally not advisable to try to manually "raise" events in this fashion. The only time where I've seen it useful to "raise" events in this way is when performing automated UI testing - and to my knowledge, what methods we have that allow raising these events are likely internal methods.
It's generally not advisable to try to manually "raise" events in this fashion. The only time where I've seen it useful to "raise" events in this way is when performing automated UI testing - and to my knowledge, what methods we have that allow raising these events are likely internal methods.
I want to simulate a tool click in my unit test. For some of Infragistics controls I have seen RaiseEVENT methods. Is there similar method for ToolClick.
Hello Vince,
thats a great hint.I never thought about this opportunity. But it works fine, thanks a lot.I have an application where I can drill from one view to another. by that way of open the other view there are some settings, who will be set depending on the view I'm on.In this case I have to raise the functunality of a tool from the new view to get the right information shown.Its difficult to explain here :-)
Have a nice day and a great weekend.
My recommendation is to encapsulate the functionality you want to occur on a particular tool click into its own method. You can then call this method from the ToolClick event of the WinToolbarsManager, or programmatically from any other location where you want to perform the same functionality.
For instance, say I want to have a "Save" tool that saves the current file I'm editing. I also want to have a "Save" button that, when clicked, does the same thing. I'd write a "SaveFile()" method, which I'd call from the ToolClick event when the Save tool is clicked, as well as from the button's Click event.