I’m using WinForms to design an application. It has many controls (buttons, menus, etc) that have underlying event handlers. I find that my class is getting rather large and hard for one person to navigate. This is due to the fact that each control requires one or more methods to handle events within the context of the window.
What are some techniques for organizing these methods or splitting up such a large class?
If it is just about navigation you can split your class in several files, just add the
partialbefore the class declaration in every file.Generally if you have some very complex controls or event handlers bound to these controls it can be reasonable to separate those in your own custom user controls and just add them to your form. Just add a new user control element to your project and customize it the way you need.
All your controls are immediately available as any other .Net controls in the same project, but you might also want to put them in a separate DLL file (if you want even more separation of your code).
Here is a nice tutorial how to design your own controls in WinForms.