circler
circler

Reputation: 369

Organizing code in c# using 1 Form and a lot of functions

I am writing a program that has like 8 tabs in one form. Each tab does different functionality so as you know it requires a lot of methods/variables/classes/background workers etc..

I used to write similar programs before but the MainForm.cs file had a lot of code and it made it very messy( a lot of controls, on click events, etc..)

What is the best way to organize the code in such case?

Are there any documents or examples to follow?

Please let me know!

Upvotes: 3

Views: 1420

Answers (3)

Shell
Shell

Reputation: 6849

Create user controls for each tab page and place all control in their separate user control for each page. Thus, your code will be separated in their usercontrol. You can also invoke their method and handles it's events from your main form.

Upvotes: 2

Josh Anderson
Josh Anderson

Reputation: 438

If everything HAS to be in one class, I'd try partial classes out. You can make a new .cs file for every tab and add it to your project, but everything will still be in the same class.

http://msdn.microsoft.com/en-us/library/wa80x488.aspx

Upvotes: 3

John Yost
John Yost

Reputation: 693

The best solution I've found is MDI Child Forms. Each tab can be created as a separate form then added during initialization. I also believe you can drop these into a tab form, see here.

Good luck!

Upvotes: 0

Related Questions