Results 1 to 6 of 6

Thread: User Control Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    Allen, Texas
    Posts
    125

    User Control Help

    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.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    When you say access the textbox, what are you trying to do with it?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    Allen, Texas
    Posts
    125

    Textbox

    Read and write to the text box.

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    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:
    1. 'Code in your usercontrol
    2. Option Explicit
    3.  
    4. Public Property Get Text() As String
    5.     Text = Text1.Text
    6. End Property
    7.  
    8. Public Property Let Text(ByVal New_Text As String)
    9.     Text1.Text = New_Text
    10.     PropertyChanged "Text"
    11. End Property
    12.  
    13. Private Sub UserControl_InitProperties()
    14.     Text = UserControl.Extender.Name
    15. End Sub
    16.  
    17. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    18.     Text1.Text = PropBag.ReadProperty("Text")
    19. End Sub
    20.  
    21. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    22.     PropBag.WriteProperty "Text", Text1.Text
    23. End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    Allen, Texas
    Posts
    125

    Well

    Thanks!

    How do I use this from the main program?

    Do I just call it like a normal control?

  6. #6
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Attached is a quick sample.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width