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 / April 2005

Tip: Looking for answers? Try searching our database.

Extending TextBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Anthony Spiteri - 19 Apr 2005 09:59 GMT
Hi,

I am trying to extend a TextBox and require that I assign a default value to
it's Text property. However the problem is that the Text property will still
get the default .NET framework value (usercontrolnameXXX).

The code I am using is as follows:

       public class UserControl1 : System.Windows.Forms.TextBox
       {
               private System.ComponentModel.Container components = null;

               public UserControl1()
               {
                       InitializeComponent();
                       base.Text = "red";
               }

               [DefaultValue("red")]
               public override string Text
               {
                       get
                       {
                               return base.Text;
                       }
                       set
                       {
                               base.Text = value;
                       }
               }
       }

The problem seems to lie within "base.Text = value", since if I comment out
that line everything works fine.

This code works perfectly for other properties so I cannot seem to
understand where the problem lies.

Any advice will be appreciated.

Thank You,
Mark Anthony Spiteri
http://blog.mspiteri.com
MrSnorkle - 20 Apr 2005 09:45 GMT
Hi,
the Default Attribute is not for setting the default Value, its for the Designer to know, that a given Value IS the Default, and if the value differs from the one in the Default Attribute, the Designer will display it in bold.
to set the initial value, assign it in  the initializecomponent function.

Hope this helps.

MrSnorkle

-------- Original Message --------
Subject: Extending TextBox (19-Apr-2005 10:59)
From:    Mark Anthony Spiteri <mark@[remove]mspiteri.com>
To:      microsoft.public.dotnet.framework.windowsforms

> Hi,
>
[quoted text clipped - 42 lines]
> Mark Anthony Spiteri
> http://blog.mspiteri.com

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.