Search code examples
controlsgambas

Create Controls in Gambas with dynamic Eventname


In Gambas I can create Controls like this:

btn = New Button(parent) As "MyButton"

Now events listen on:

MyButton_Click()

But how can I create Elements with dynamic name, like:

dim tmp as string
tmp = "MyButton"
btn = New Button(parent) As tmp

The last line does not work, but thats the question how to handle this.


Solution

  • I have to attach the Object to its Parentform with this:

    dim tmp as string
    tmp = "MyButton"
    
    btn = New Button(parent)
    Object.Attach(btn, ParentForm, tmp)