Can control properties on base Form be changed on derived Form?

P

Peter Rilling

Hi,

When I have a base Form that I add controls to, then inherit that Form, when
the derived class is viewed in the designer, the controls that were placed
on the base are visible, but all the properties are locked.

What I would like to do is to use controls in the base that act like a
template where the base has certain (default) controls defined, but then the
subforms to override some or all of those properties. For instance, suppose
a Label was placed on the base Form at some default location, I would still
like the derived class to be able to move. Another example is if I have a
ListView that has some default columns defined. I would like the derived
class to be able to add more columns if necessary.

Is this possible within the constraints of VS's designer support?
 
O

opellegr

Have you tried changing the Modifiers property of each control in the
designer property grid? By default, all controls are private, which means
the derived class won't be able to access them. If you change it to an
appropriate non-private value, the derived class should be able to modify the
properties of the controls.
 
P

Peter Rilling

Great, this works.

A related questions. In the scenario I laid out, is it possible to have the
derived form told to "delete" the control eventhough the base is still
defining it. I have seen that I can change the properties of controls
defined in the base Form, but when I select one of those and try to remove
it from the designer, no good.
 
O

opellegr

You cannot remove members of a base class as far as I know. Once a member is
inherited it will always be present. In a way, it's as if a derived class is
an instance of two classes: one of the base class and one of itself.

Still, you could set the Visible property of the controls you do not want to
display to false. This would keep them from being displayed on the derived
form. It *might* be a memory-saver to dispose of them as well in your
derived constructor or Load event, but that could be a mistake if there's
anything in the base class that accesses the control. I'd test disposing the
control heavily before releasing something like that.
 
G

Gregg Walker

A related questions. In the scenario I laid out, is it possible to have
the derived form told to "delete" the control eventhough the base is still
defining it. I have seen that I can change the properties of controls
defined in the base Form, but when I select one of those and try to remove
it from the designer, no good.

You cannot delete controls (or any other properties, methods, fields) from
an inherited form (class). You could set the control's visible property to
false making it appear to be gone as opellegr replied.

However another option in this case is to use Item/Project Templates as
opposed to Class Inheritance. The templates can be used to create a new
form with a base set of controls you commonly use but also allow you to
delete controls, properities, methods and fields that you don't need for the
created instance.

I actually prefer templates over inheritance in most cases for common forms
and project types.

hth
 
R

Ramesh Shakya

I worked for he Button control,But I have a problem here,It did not work for the toolstrip control even if I made it and all the tool buttons public.



Gregg Walker wrote:

You cannot delete controls (or any other properties, methods, fields) from an
30-Jan-08

You cannot delete controls (or any other properties, methods, fields) from
an inherited form (class). You could set the control's visible property to
false making it appear to be gone as opellegr replied

However another option in this case is to use Item/Project Templates as
opposed to Class Inheritance. The templates can be used to create a new
form with a base set of controls you commonly use but also allow you to
delete controls, properities, methods and fields that you don't need for the
created instance

I actually prefer templates over inheritance in most cases for common forms
and project types

ht
-
Gregg Walker

Previous Posts In This Thread:

Can control properties on base Form be changed on derived Form?
Hi

When I have a base Form that I add controls to, then inherit that Form, when
the derived class is viewed in the designer, the controls that were placed
on the base are visible, but all the properties are locked

What I would like to do is to use controls in the base that act like a
template where the base has certain (default) controls defined, but then the
subforms to override some or all of those properties. For instance, suppose
a Label was placed on the base Form at some default location, I would still
like the derived class to be able to move. Another example is if I have a
ListView that has some default columns defined. I would like the derived
class to be able to add more columns if necessary

Is this possible within the constraints of VS's designer support?

Have you tried changing the Modifiers property of each control in the designer
Have you tried changing the Modifiers property of each control in the
designer property grid? By default, all controls are private, which means
the derived class won't be able to access them. If you change it to an
appropriate non-private value, the derived class should be able to modify the
properties of the controls

:

Great, this works.A related questions.
Great, this works

A related questions. In the scenario I laid out, is it possible to have the
derived form told to "delete" the control eventhough the base is still
defining it. I have seen that I can change the properties of controls
defined in the base Form, but when I select one of those and try to remove
it from the designer, no good



You cannot remove members of a base class as far as I know.
You cannot remove members of a base class as far as I know. Once a member is
inherited it will always be present. In a way, it's as if a derived class is
an instance of two classes: one of the base class and one of itself

Still, you could set the Visible property of the controls you do not want to
display to false. This would keep them from being displayed on the derived
form. It *might* be a memory-saver to dispose of them as well in your
derived constructor or Load event, but that could be a mistake if there's
anything in the base class that accesses the control. I'd test disposing the
control heavily before releasing something like that

:

You cannot delete controls (or any other properties, methods, fields) from an
You cannot delete controls (or any other properties, methods, fields) from
an inherited form (class). You could set the control's visible property to
false making it appear to be gone as opellegr replied

However another option in this case is to use Item/Project Templates as
opposed to Class Inheritance. The templates can be used to create a new
form with a base set of controls you commonly use but also allow you to
delete controls, properities, methods and fields that you don't need for the
created instance.

I actually prefer templates over inheritance in most cases for common forms
and project types.

hth
--
Gregg Walker


Submitted via EggHeadCafe - Software Developer Portal of Choice
Six Free Visual Studio 2010 MSDN Memberships Giveaway
http://www.eggheadcafe.com/tutorial...al-studio-2010-msdn-memberships-giveaway.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top