Reputation: 747
I am writing a BaseForm to be inherited. The BaseForm has some basic standard controls of my application.
The problem is: I want allow inherited forms to use and change this controls, but not remove they from the form.
The biggest problem is a TabControl which Tabs must be added by users Inherited Forms. If I set "Modifiers" properties of TabControl on BaseForm to private, then inherited Forms will not be able to add new Tabs. If I set "Modifiers" properties of TabControl on BaseForm to protected, the inherit Forms can remove the TabControl from the BaseForm.
There is a away to stop this? Custom Design?
Upvotes: 1
Views: 2457
Reputation: 44307
If you want your forms to behave "nicely" within the Visual Studio designer, then you're out of luck - having the Tab Control private will work when you're editing the parent form directly, but will fail when you try to edit descendants.
I believe @Michael Meadows is correct with his answer - having built elaborate frameworks myself in the past that failed to deliver what I wanted.
Broadly speaking, where you're looking at pulling things together with inheritance, I believe that composition will serve you better. At least, this is my experience.
For lightweight ideas, check out Jeremy Millers series of blog posts Build your own CAB - lots of good material.
Upvotes: 1
Reputation: 28416
Gustavo,
You're standing at the bottom of the first foothill of a mountain range of problems that you'll experience by forcing developers to inherit from a "base form class." From my experience, frameworks built in this way tend to be very fragile, and difficult for developers to use.
I would imagine that you can overcome this particular obstacle by making the TabControl private and then implementing a public "Tabs" property on the form itself, but I also suspect that you'll get to the peak of this mountain and realize that you have many other even taller mountains in front of you. I would suggest you rethink the approach altogether.
// set the Modifiers property on tabControl1 to "Private" then implement this
public TabControl.TabPageCollection TabPages
{
get { return tabControl1.TabPages; }
}
Inheritance should be used provide common functionality, not to provide a uniform composition. You really should consider implementing a "core screen" and designing your framework to allow developers to "plug" their controls in to that screen.
The Composite UI Application Block is a good place to start, although there may be something more recent that I'm not aware of.
Upvotes: 4