Subclassing TextBox

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
 
M

Marina

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.
 

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