Results 1 to 2 of 2

Thread: [RESOLVED] load a component inside usercontrol

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] load a component inside usercontrol

    how can i load a button for example inside a usercontrol in runtime?

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: load a component inside usercontrol

    The same way you would do it on the form:
    Code:
    'add this code to your user control
    Option Explicit
    
    Dim WithEvents btn As CommandButton
    
    'assuming your user control has a button "Command1" - otherwise use this part of code elsewhere
    Private Sub Command1_Click()
    
        Set btn = UserControl.Controls.Add("VB.CommandButton", "btnTemp")
        btn.Move 100, 100
        btn.Caption = "Test"
        btn.Visible = True
    
    End Sub
    
    Private Sub btn_Click()
        MsgBox "Hello World!"
    End Sub
    Note: you can also use control array.

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