Page 1 of 1

How do I use 'created' controls?

Posted: Tuesday 27th April 2021 6:04am
by Doctor Watson
Well, here’s another beginners question.
I’m trying for the first time to ‘create’ a Control and use it, like this:
' Gambas class file
Public MyButton As New Button(Me)

Public Sub Form_Open()
    
  With MyButton
    .top = 10
    .left = 50
    .width = 60
    .height = 30
    .text = "Click !"
  End With
  
End

Public Sub MyButton_Click()
Quit
End
Everything looks fine. The button appears where it should. Gambas doesn’t throw any errors at me.
So why doesn’t clicking MyButton work?
I can’t find any really clear and simple examples on how to use created controls.

Re: How do I use 'created' controls?

Posted: Tuesday 27th April 2021 8:12am
by BruceSteers
You need to set the handler name using As

Dim myButton As Button = New Button(Me) As "MyButton"

Probably best to not create the button in the public namespace and put on the form open function.

So...

Public MyButton As Button

Public Sub Form_Open()

With MyButton = New Button(Me) As "MyButton"

Etc....

Re: How do I use 'created' controls?

Posted: Tuesday 27th April 2021 9:33am
by Doctor Watson
Thanks Bruce.
Now I'm getting somewhere .....
But it would be a lot easier for a beginner if there were some examples to be found, wouldn't it.
Another bite of the elephant gone ;)

Re: How do I use 'created' controls?

Posted: Tuesday 27th April 2021 11:36am
by cogier
But it would be a lot easier for a beginner if there were some examples to be found, wouldn't it.
Have a look at this example here.

The use of Quit is not recommended for GUI programs, you should use Me.Close.

Re: How do I use 'created' controls?

Posted: Tuesday 27th April 2021 12:34pm
by BruceSteers
Doctor Watson wrote: Tuesday 27th April 2021 9:33am Thanks Bruce.
Now I'm getting somewhere .....
But it would be a lot easier for a beginner if there were some examples to be found, wouldn't it.
Another bite of the elephant gone ;)
You are using the New keyword.
See the wiki for New
http://gambaswiki.org/wiki/lang/new

the examples you have not yet found are there.

Less speed more read my friend ;)