views:

469

answers:

3

I have several forms in a .net windows app that have a common set of textboxes and other user input controls,each form has the same look and feel, but each form needs to load and save to different database tables.

Would it be better to place the controls on a base form, and inherit from it or to create a user control to drop on each form?

+1  A: 

I usually prefer UserControls as they are more flexible - you can use them in the context of a form, or in any other visual context to display or modify data. I've had several cases where I had to change my UI design from a separate dialog to edit something to an inline control inside the main form or something like that.

Other than that, I'd say it's a matter of taste.

Phil Reif
A: 

It depends. Composite model (using User Control) is cleaner, but the control cannot be aware of the calling form, so you have to pass the logic in as events. That sometimes can lead to duplicate logic.

With inheritance, you can implement common code at the base class with some override at the subclass form and implement flexible interplay. But that requires all implementers of the subclass to be aware of the base class source code, which can get chaotic.

eed3si9n
+1  A: 

I use both methods, depending on the situation. If you have a functional piece of LOGIC that you want to just drop into a form unmodified, then I think that UserControls are appropriate. However, if you're just looking to duplicate and extend a common UI across multiple forms, then visual inheritance is probably the better option.

DannySmurf