Extending TextBox

G

Guest

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
 
M

MrSnorkle

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)
 

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

Top