Results 1 to 6 of 6

Thread: Dynamic Controls

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Oxfordshire
    Posts
    13

    Question


    How can you add events to controls added in runtime
    using the ADD method?

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'add a command button to a form dynamically at run time
    
    Option Explicit
    
    Private WithEvents btnObj As CommandButton
    
    Private Sub btnObj_Click()
       MsgBox "This is a dynamically added button."
    End Sub
    
    Private Sub Form_Load()
       Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
       With btnObj
          .Visible = True
          .Width = 3000
          .Caption = "This button was created on the fly!"
          .Top = 1000
          .Left = 1000
       End With
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    New Member
    Join Date
    Nov 2000
    Location
    England
    Posts
    3
    Originally posted by Rwhite

    How can you add events to controls added in runtime
    using the ADD method?


    Try using the CreateEventProc Method. If this doesn't help, let me know.

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    johnson_m

    Code:
    If you use the code I pasted the events come with the button. All you have to do is use them..ie> 
    Private Sub btnObj_Click()
       MsgBox "This is a dynamically added button."
    End Sub
    or any other event belonging to the control created...you just have to choose to use.
    
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    How would you make more than one?
    retired member. Thanks for everything

  6. #6
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Same way as you made the first.
    Donald Sy - VB (ab)user

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