Inheriting Methods

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

Guest

I have a text box class, in which I want this code to run each time the
textbox gets the focus:

this.Text = this.Text.Trim()

How do I wire this up?

I can wire it up at the form level, but then I have to put the code in each
text box in the Enter Event.

The textbox base class is currently and empty shell that looks like this:

class TextBoxBase: TextBox
{
}

Thanks,

Greg
 
Greg said:
I have a text box class, in which I want this code to run each time the
textbox gets the focus:

this.Text = this.Text.Trim()

How do I wire this up?

I can wire it up at the form level, but then I have to put the code in
each
text box in the Enter Event.

The textbox base class is currently and empty shell that looks like this:

class TextBoxBase: TextBox
{
}

I wouldn't use TextBoxBase, since there is already a class in the .NET
Framework called that.

class TrimTextBox: TextBox
{
protected override void OnEnter(EventArgs e) {
base.OnEnter(e);

Text = Text.Trim();
}
}
 

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

Back
Top