How do I use 'created' controls?

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

How do I use 'created' controls?

Post 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.
Old african saying:
You eat an elephant one small bite at a time.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How do I use 'created' controls?

Post 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....
If at first you don't succeed , try doing something differently.
BruceS
Doctor Watson
Posts: 84
Joined: Wednesday 22nd August 2018 7:55am

Re: How do I use 'created' controls?

Post 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 ;)
Old african saying:
You eat an elephant one small bite at a time.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: How do I use 'created' controls?

Post 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.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How do I use 'created' controls?

Post 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 ;)
If at first you don't succeed , try doing something differently.
BruceS
Post Reply