Click here to Skip to main content
15,877,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been programing in windows forms for two years. Unfortunately I didn't explored what is the best practice to handle a lot of code in Forms.cs I have been using Manager classes for each controls and event handlers in seperate classes other than form. But I don't know if there is some better way for managing a lot of code of a single form. keeping best memory utilization. I need references to some good articles. Can you help me learning.
I am developing ERP system whose code increase with time.
Looking forward to know from you.

Well, as goes with any Object Oriented Programming language the OOP conctepts are always a good practice. This is not specific to WinForms.
Introduction to Object Oriented Programming Concepts (OOP) and More[^]
Principles of OOD (SOLID)[^]

Now when building applications multi-layered architecture[^] keeps your data, business and presentation logic apart from each other. Actually the multi-tiered architecture[^] is also considered best practice (kind of extends or implements SOLID).

Now how does such stuff work in the presentation layer? For this there are a couple of well known patterns. In WinForms (but also web development) we have mostly MVC (Model View Controller)[^] and MVP (Model View Presenter)[^].
Here are some interesting discussions about the pro's and cons to both approaches in WinForms:
WinForms Model View Presenter[^]
MVC vs. MVP for a WinForms app[^]
Is MVC/MVP an anti-patterns in WinForms?[^]
Selecting an MVC/MVP Implementation for a WinForms Project[^]
Model-View-Presenter (MVP) Design Pattern with .NET - WinForms vs. ASP.NET WebForms[^]
Pick a few :)

I hope that gives you some idea's to best practices, writing maintainable and flexible code etc.
By the way, what also helps towards this goal is keeping your code consistent. Naming conventions and programming standards[^] help others to understand your code.
Hope it helps! :)
Share this answer
Go here [^]

If you want to find articles on codeproject, just add "codeproject" to whatever you type in the search field.
Share this answer
Sander Rossel 29-Nov-11 17:33pm    
Sorry John, but not agreeing with you there. Google could be the answer to any question anyone has, but you have to know what to search for... Clearly the OP tried and got stuck at some point. See my answer for (hopefully) a push in the right direction :)
#realJSOP 30-Nov-11 6:16am    
You can say that with a straight face with all of the links you posted for the OP? A concerted google search would have revealed ALL of those if he had just put in a little effort. Besides that, without performing at least a cursory code review and requirements evaluation, there's NO WAY we could give him a definitive best practice recommendation.
Sander Rossel 30-Nov-11 13:38pm    
True. And I admit it's quite a lot of links, but I'm actually quite interested in the subject. Guess I got a bit carried away :)
Anyway, I already knew I had to Google MVC and/or MVP + WinForms...
I didn't univote you by the way. Google often is the best solution. Just saying the OP might've needed a push in the right direction (so I bazooka'd him in the right direction, I'm sure you've bazooka'd people in various directions as well ;p ).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900