Subclassing TextBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I subclassed a TextBox, but I can't get it to change the default Text
property. Whenever I create a new control based on this, it still gets
created with the Text value "myTextBox1". What am I doing wrong?

using System;
using System.Windows.Forms;

namespace MyControls
{
public class MyTextBox : TextBox
{
public MyTextBox()
{
this.Text = "";
}
}
}

TIA,

Mike Rodriguez
 
There is probably design time code written for the TextBox class that is
executing here. This code sets the property immediately after Textbox
creation. This means, that after your constructor is run, that property is
set. So you set it to empty string, and the design time code sets it to the
name of the control.

I can't think of any other way, but for you to change the designer for your
class to be something else. Look into the ControlDesigner class.
 
Back
Top