Is there a prettier way to handle lots of controls with lots of Click events?

Sounds like a silly questions.  I used to program in VS (VB and C++) quite awhile ago.  I'm back in the MS world of programming and like a lot of the new features.  However, I'm wondering if we can group the click events or maybe create a subclass in the main class to handle the events.  

In short, I'm looking at a class that is more than 20 pages long with a lot of methods and click events, thinking there has got to be a better way.  Any ideas?

Thanks,
Patricia
pdlarueAsked:
Who is Participating?
 
nguyenvinhtuCommented:
Normally, we create an Handler for a user-defined event. to event of .NET control, such as, click, load, etc. we need to use System.EventHandler. If we define a delegate and event for our user control, it's ok too.
Your idea sound good if we group all reuse function in a class. Then use it for our event handler.
If you have two or more button which is handled by the same function, we use this:
this.button1.Click += new System.EventHandler(this.MyHandler_Click);
this.button2.Click += new System.EventHandler(this.MyHandler_Click);
0
 
ThogekCommented:
Might depend on what you're click-event-handling method look like.  Are they all very similar to eaach other, and/or is there a lot of overlapping/duplication functionality that could be abstracted into helpful methods, etc.

Also, if you're looking at a single page/form/control that has a lot of UI elements (and their respective event handlers) all over it, it might be worth grouping those elements into composite controls that each focus on a certain functional group.  (So you could have a page/form that has a handful of controls, and each control contains a handful of child controls, etc.)

It'd be difficult to be much more specific without seeing some examples of what you're dealing with...
0
 
pdlarueAuthor Commented:
Thank you, nguyenvinhtu, your answer leads me to believe that .NET code can be written using the standard Microsoft default structure or it can be written using a more Java like structure.  If this is true then we can write these events in a separate class for reusability.  I will explore this concept further.  Thank you for your reply.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.