Suppose I have this UserControl with three TextBoxes (First, Middle, and
Last Names).

I want to only expose out the Text property and the TextChanged event to
consumers of the UserControl.

So taking a look at just one of the TextBox controls, FirstName, I have no
problems with just a passthrough property on the Text value of the actual
private control (see code below).

My question is about my FirstNameChanged event.  I have written Changed
events from scratch on properties that are carried by my control in just
some private variable ([PropertyName]Changed/On[PropertyName]Changed/on
[PropertyName]Changed stuff),  but this time instead of a private variable,
the property is rooted in a private Control...which already has it's own
implementation of the [PropertyName]Changed event.

Does anyone see any problem just passing through the add and remove from
the control's consumer?  This looks like it works fine as I test it. I site
the usercontrol on a form, then subscribe to the FirstNameTextChanged event
and everything acts properly on FirstNameText sets, as well as when you
type in the textbox control.

It's just feels odd enough to make me wonder if anyone can see any obvious
flaws in it??  Thanks for any insight anyone can give.

Jeff


public class NameControl : System.Windows.Forms.UserControl
{
  private System.Windows.Forms.TextBox txtFirstName;

  <snip constructor and lots of other code for brevity>

  public string FirstNameText
  {
    get {return this.FirstName.Text;}
    set {this.txtFirstName.Text = value;}
  }

  public event EventHandler FirstNameTextChanged
  {
    add {this.txtFirstName.TextChanged += value;}
    remove {this.txtFirstName.TextChanged -= value;}
  }
}

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to