[Last Call] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-05-08
Medium Priority
Last Modified: 2010-04-16
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?

Question by:pdlarue
LVL 15

Expert Comment

ID: 16635002
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...

Accepted Solution

nguyenvinhtu earned 2000 total points
ID: 16635732
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);

Author Comment

ID: 16709960
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.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Screencast - Getting to Know the Pipeline
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question