views:

342

answers:

2

I am relatively new to VS and C# but have years of experience in Delphi. One of the my favorite components when designing GUI in Delphi is ActionManager - centralized way to assign event handlers for actions as well as enabling/disabling them. Surprisingly, I can't find anything like this in Visual Studio 2008 Professional. I am sure that there should be third party implementations but I'd prefer something standard.

Can anybody suggest me something for this? Maybe there is some alternate way to effectively manage GUI actions that I am missing?

+3  A: 

In WPF there are Commands, which are conceptually similar.

Craig Stuntz
Thank you, this seems very close but unfortunately is not available for WinForms. I am not sure if it is time to move to WPF but it seems that MS positions WinForms as obsolete technology. Not very good for them.
koldovsky
+2  A: 

I loved ActionManager, too. I did not know it at that time, but all it is is a fancy implementation of Model-View-Controller. In hindsight, Delphi was too advanced for an unprepared developer community 8-)

Back to your question, C# has the concept of events and delegates, which are equivalent to actions and their handlers. You tie control events (or GUI actions) to delegates. For example,

mybutton.Click += HandleMyButtonClick;

Click would be a delegate with the signature void (object sender, EventArgs e). This signature would be followed by the HandleMyButtonClick method, like this.

void HandleMyButtonClick(object sender, EventArgs e)

Under the class documentation of controls, there will be a section listing all the events that are raised. These events will also describe the signature of the delegates required to handle them.

jeyoung
May I ask why the negative score?
jeyoung
I did not downvote, but actions do more then just calling a method. They also provide a central place to provide a Caption, an Image and a way to "Update" the action like disabling it.
Lars Truijens
Hence my use of "fancy implementation of MVC" 8-) The original post was unclear about how close to ActionManager he wanted an alternative to be. I assumed he did not know about delegates and events, and that he could build his own ActionManager with this knowledge.Thanks for the justification anyway.
jeyoung
I do not know who scored negative. It seems that system of votes is not perfect. I like your answer, though it did not bring anything new for me. In any case thanks for answering.
koldovsky