Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Rilling - 29 Jan 2008 21:33 GMT
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?
opellegr - 29 Jan 2008 21:46 GMT
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.

> Hi,
>
[quoted text clipped - 11 lines]
>
> Is this possible within the constraints of VS's designer support?
Peter Rilling - 29 Jan 2008 23:48 GMT
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.

> Have you tried changing the Modifiers property of each control in the
> designer property grid?  By default, all controls are private, which means
[quoted text clipped - 24 lines]
>>
>> Is this possible within the constraints of VS's designer support?
opellegr - 30 Jan 2008 15:23 GMT
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.

> Great, this works.
>
[quoted text clipped - 3 lines]
> defined in the base Form, but when I select one of those and try to remove
> it from the designer, no good.
Gregg Walker - 30 Jan 2008 16:29 GMT
> 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
--
Gregg Walker

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.