473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Visual Inheritance - How to make public inherited properties private or readonly?

Let's say I create a custom component that inherits from TextBox. Then
I set the color of the textbox. Now I want it so that anyone who uses
this component can not change the color. How do i make it so that the
BackColor property is no longer able to be set (either at runtime or
design time) for my new custom text box?

Mar 23 '06 #1
2 1413
Mi************@gmail.com wrote:
Let's say I create a custom component that inherits
from TextBox. Then I set the color of the textbox.
Now I want it so that anyone who uses this component
can not change the color.


You can't "hide" a base class' public member, as it would defeat the
point of polymorphism. Perhaps you can override OnBackColorChanged and
immediately set the colour back to what it was before.

Eq.
Mar 23 '06 #2
Paul is right: you can't _completely_ hide the BackColor property, but
perhaps this might work for you:

private new Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}

If you just want it hidden in the property browser at design time, but
not hidden in code, you can do this:

[Browsable(false)]
public override Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}

Mar 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jason Hickey | last post by:
Has there been a change in the way the UI designer handles winform inheritance in the 2003 version of visual studio. Consider the following (try it if you are using 2003 Everything seems to work...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
26
by: Michael A. Covington | last post by:
Suppose class X has some public properties, and class Y inherits from X. Is there a way that some of the public properties of X can be private (hidden) in Y (but still usable by the methods...
10
by: Kishor | last post by:
Hi, I am looking for the solution to my problem. this is related to inheritance (Inheriting properties of base class in multiple quantity) . I am writing code in VB.net language, I am having two...
15
by: gwolinsky | last post by:
I originally posted this in the WindowsForms group but that may not have been the best place to post it. So, I am reposting here. -------------------------------------- I am trying to...
6
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
3
by: tshad | last post by:
I am playing with Inheritance and want to make sure I understand it. I have the following Classes: ******************************************* Public Class AuthHeader:Inherits SoapHeader Public...
8
by: RSH | last post by:
Being rather new to OOP constructs I have a question regarding inheritance. What is the proper way to setup my classes in a Company/Employee relationship. I have a Company Object and a company...
3
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.