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 / ASP.NET / Building Controls / March 2007

Tip: Looking for answers? Try searching our database.

Removing a property from a custom control derived from TextBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mc - 10 Mar 2007 17:33 GMT
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>
    }
Steven Cheng[MSFT] - 12 Mar 2007 08:22 GMT
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.
mc - 12 Mar 2007 10:20 GMT
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

> Hello MC,
>
[quoted text clipped - 71 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Steven Cheng[MSFT] - 12 Mar 2007 11:29 GMT
You're welcome ;-)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

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.