ken_reiss

Event Handler for objects that are created programmatically

Discussion created by ken_reiss on Oct 16, 2009
Latest reply on Dec 2, 2013 by fabiano.batista

Hello all,

 

I'm trying to build controls programmatically and also their event handlers, can this be done?

 

Here is what I have so far for a little test, but I can't get the event handler to work.  This code is contained in a Class Module

Private WithEvents Dis As Display
Private WithEvents test As Text

Private Sub Class_Initialize()
    Set Dis = Application.ActiveDisplay
    Set test = Dis.Symbols.Add(pbSymbolText)
    test.Contents = "My Text Symbol"
    test.LineColor = 0
    test.BackgroundColor = -1
End Sub

Private Sub test_Click(ByVal lvarX As Long, ByVal lvarY As Long)
    MsgBox ("hello")
End Sub

 I've also tried the following with no success:

Private WithEvents Dis As Display
Private WithEvents test As Text

Private Sub Class_Initialize()
    Set Dis = Application.ActiveDisplay
    Set test = Dis.Symbols.Add(pbSymbolText)
    test.SetName "test"
    test.Contents = "My Text Symbol"
    test.LineColor = 0
    test.BackgroundColor = -1
End Sub

Private Sub test_Click(ByVal lvarX As Long, ByVal lvarY As Long)
    MsgBox ("hello")
End Sub

Attachments

Outcomes