views:

74

answers:

4

I am wondering how to handle a Form with a lot of controls. Do you stuff all of the handling code into the Form? This is how I have been doing it, but my most recent project is getting out of hand because of all of the controls that I need to work with. I have menus, multiple toolbars, tabcontrols filled with controls, statusbar, ... you get the idea. I am thinking of using partial classes to split up things, but that's probably a bad idea. I just need some advice on what I should do.

+8  A: 

I would recommend using UserControls to break up your functionality. By moving independent pieces into UserControl instances, you can segregate your logic.

In addition, using an architectural pattern like MVC or MVP can help tremendously as an application gets larger.

Reed Copsey
MVC for the win.
JustBoo
+1  A: 

You should divide the controls into logical groups by functionality, then move each group to its own UserControl.

SLaks
+2  A: 

If you're building something along the lines of a major form like you describe, you really should be developing an architecture with a defined business and data layer. Your actual functionality and manipulation should be separated into a class library built specifically to handle the abstracted information/operations. The same with data calls and processing. These should be abstracted into a separate library that is responsible for managing input/output operations to your data sources.

What this does is reduce the code in your actual form to the elements that are actually necessary to manage the display and immediate behaviors (clicks, rollovers, menus, etc). Even some of that can be combined if you effectively manage your form states. The gist is that you want to make sure to abstract as much away from the form as possible and leave the form's responsibility to be immediate display.

Joel Etherton
A: 

Best Idea for simple applications is to moved the independent controls to UserControls or use MVVP pattern, though it is little time consuming for learning and implementing, but down the line it eases off your effort to implement new features.

Naresh