Removing a property from a custom control derived from TextBox

M

mc

I have created a Custom control which automatically grows a TextBox to
fit the text that is being entered, consequently this control must be a
MultiLine TextBox. I would like to remove the "TextMode" Property, the
closest I have achieved so far is to change the property to a Get only one.

Is there a better solution?

TIA


MC

-------------------------

public class AutoResizeTextBox : System.Web.UI.WebControls.TextBox
{
public override TextBoxMode TextMode
{
get
{
return base.TextMode;
}
}

<snip>Rest of Code</snip>
}
 
S

Steven Cheng[MSFT]

Hello MC,

As for hidding a property(function) in base class, so far the .net
framework programming language (C# and VB.NET) doesn't provide a direct
means to do this. What you can get is use a "new" keyword (in C#) to
redefine a property(method) and them use some .NET specific attribute to
decorate it.

For example ,you can use the "BrowsableAttribute" to make your control's
"Text" property invisible in IDE designer's property windows. You can also
use "ObsoleteAttribute" to make the property unusable(report error at
compile time if you try using it). e.g.

======================

public class MyTextBox :TextBox
{
public MyTextBox()
{

}


[Obsolete("This property is no longer used in this control", true)]
[Browsable(false)]
public new string Text
{
get { return "not used..."; }
}


}
===========================

#ObsoleteAttribute Class
http://msdn2.microsoft.com/en-us/library/system.obsoleteattribute.aspx

#BrowsableAttribute Class
http://msdn2.microsoft.com/en-us/library/system.componentmodel.browsableattr
ibute.aspx

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

mc

Over the weekend I'd spotted the EditorBrowsable and Browsable
attributes, but I've not come across the Obsolete attribute. That along
with the new keyword does the job nicely.

It's been pointed out elsewhere that someone can cast my control as a
TextBox and still access the property.

Thank you for not launching into a philosophical OO rant about how bad
it is to try and remove an inherited property!

Thanks


MC
 
S

Steven Cheng[MSFT]

You're welcome ;-)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top