I’m using a TabControl in my form and it made me wonder. Right now I have only two tabs and I store procedures relating to both tabs (button handlers, &c.) in the code for the main form, so it looks like this:
public partial class MainForm : Form
{
// ----------TAB1-----------
tab1SearchButtonCLick() {...}
tab1AddButtonCLick() {...}
// ----------TAB2-----------
tab2EditButtonCLick() {...}
tab2SearchButtonCLick() {...}
tab2ClearButtonCLick() {...}
}
That’s not a problem now with so little code, but it might be one in the future. Is this an acceptable way of doing this? What’s the alternative? I believe I could put the tabs in their own classes, but I’m not sure how I’m going to do that exactly (there’s lots of controls in each tab that I’d have to pass as arguments to constructors).
You should move the contents of each tab to a separate UserControl.
Each UserControl should be a self-contained unit that gets whatever data in needs from the main form and fires events to tell the main form to do things.