Hi. I have a UserControl which contains a textbox. I wanted to access the textchanged event of the textbox but in the event properties of the usercontrol I don't see the events for the textbox. How can I expose and handle particular events of the child controls from the publicly exposed UserControl in Winforms with C#.
25
votes
2 Answers
40
votes
1
votes
Expose the entire TextBox as a public property in user control and subscribe to it's events the way you desire.
Example:
class myUserControl: UserControl {
private TextBox _myText;
public TextBox MyText { get {return _myText; } }
}
After doing this you can subscribe on any of its events like so:
theUserControl.MyText.WhatEverEvent += ...
Hope this helps!