Results 1 to 8 of 8

Thread: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

  1. #1

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Resolved [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

    Hello,

    I've got my UserControl, but I'm creating/referencing it on the FLY @ Runtime.

    Is there a way for it to support EVENTS without turning it in to a CLASS etc ?
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do you add Events to a DYNAMICALLY created UC OBJ ?

    Look up the VBControlExtender in the manual.

    The VBControlExtender object is primarily used when dynamically adding a control to the Controls collection using the Add method. The VBControlExtender object is particularly useful for this purpose because it provides a generic set of properties, events, and methods to the developer. Another feature of the object is the ObjectEvent event which is designed to parse any event raised by a dynamically added control. The example below declares an object variable as VBControlExtender, and sets the variable when adding a control. The example also shows how you can program the ObjectEvent event.

  3. #3

    Thread Starter
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: How do you add Events to a DYNAMICALLY created UC OBJ ?

    aaaaahaaa Nice 1 for anyone interested: msdn.microsoft.com/en-us/library/aa267210(v=vs.60).aspx
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

    A link should not be required.

    Every legal copy of VB6 comes with the necessary documentation CDs. If you do not have these CDs your copy of VB6 is not legal. It's right in the EULA.

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

    I've got a legal copy of VB6 but I don't have the documentation CD's any more as I lost them. Does that mean that my copy of VB6 is no longer legal?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

    Quote Originally Posted by dilettante View Post
    A link should not be required.

    Every legal copy of VB6 comes with the necessary documentation CDs. If you do not have these CDs your copy of VB6 is not legal. It's right in the EULA.
    However, sometimes the install of the MSDN library stuffs up and after a while VS6.0 may fail to realize you actually have the help installed alone with Visual Studios.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

    What the EULA mentions only covers "transfer rights" when you sell or give away Visual Studio 6.0 or individual separate products like VB6.

  8. #8

    Re: [RESOLVED] How do you add Events to a DYNAMICALLY created UC OBJ ?

    Code:
    Option Explicit
    ' Declare object variable as CommandButton and handle the events.'
    Private WithEvents cmdObject As CommandButton 
    
    Private Sub Form_Load()
       'Add button control and keep a reference in the WithEvents variable'
       Set cmdObject = Form1.Controls.Add("VB.CommandButton", "cmdOne")
       cmdObject.Visible = True
       cmdObject.Caption = "Dynamic CommandButton"
    End Sub
    
    'Handle the events of the dynamically-added control'
    Private Sub cmdObject_Click()
        Print "This is a dynamically added control"
    End Sub

Tags for this Thread

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