views:

417

answers:

1

Hello,

This is my scenario... I have a winForm tabControl that has a variety of fields on each tab (each tab has different fields). When the user clicks the 'Generate' button it is then supposed to pass controls from the tabControl's tab so that the called function can create an e-mail based off of the passed control's information. Each tab is a different e-mail template. The method can be called from 4 different buttons, each button being on a different tabControl page and each tabControl having different fields.

The problem I am having is that I cannot figure out a decent way to call/pass these controls. Since it is not known what tabControl button is being pressed until after runtime I am trying to create an abstract method to accept these controls because each tab has a different set of controls.

Any ideas?

+1  A: 

As someone else mentioned, you can cheat and try using

tabControl.Controls

for a quick and dirty fix.

If you want something that will be workable going forward, as well as expose you to some better design practices, I'd suggest an alternative. Create an EmailUserControl UserControl that holds all those form's fields for the email. Place that user control on the tab instead of all the individual fields. Then provide a method on the user control that generates the desired email with all the fields taken into account, and then you can pass your actual email about instead of all the individual pieces and parts that you can use to create it.

There are additional improvements available on that design, of course, but this is a great opportunity for you to get your feet wet and try something a little bit better. As you get more comfortable with the idea of UserControls, you'll recognize additional opportunities for improving your controls' design yourself. :)

Greg D
I had confused myself in terms of design. I had created a class for each tab that would act as the tabs 'class' so to speak. I've decided to create a user control for each tab and make that user control's class act as the class i had just described. Thanks for the help!
Awesome! Glad I could help. :)
Greg D