I have a user control that has a frame and a text box on it.
How can I access the text box on the user control from the program?
I was asked this question and thought I'd help a buddy out.
Printable View
I have a user control that has a frame and a text box on it.
How can I access the text box on the user control from the program?
I was asked this question and thought I'd help a buddy out.
When you say access the textbox, what are you trying to do with it?
Read and write to the text box.
The code below will expose a text property for a text box on a usercontrol (I just left the default text box name). With this code you will have a text property in the properties explorer that can be changed at design time when you place the control on your form or you could change the property at runtime through code.
VB Code:
'Code in your usercontrol Option Explicit Public Property Get Text() As String Text = Text1.Text End Property Public Property Let Text(ByVal New_Text As String) Text1.Text = New_Text PropertyChanged "Text" End Property Private Sub UserControl_InitProperties() Text = UserControl.Extender.Name End Sub Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Text1.Text = PropBag.ReadProperty("Text") End Sub Private Sub UserControl_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "Text", Text1.Text End Sub
Thanks!
How do I use this from the main program?
Do I just call it like a normal control?
Attached is a quick sample.