How do I use 'created' controls?

Post

Posted
Rating:
#1 (In Topic #648)
Regular
Doctor Watson is in the usergroup ‘Regular’
Well, here’s another beginners question.
I’m trying for the first time to ‘create’ a Control and use it, like this:

Code (gambas)

  1. ' Gambas class file
  2. Public MyButton As New Button(Me)
  3.  
  4. Public Sub Form_Open()
  5.    
  6.   With MyButton
  7.     .top = 10
  8.     .left = 50
  9.     .width = 60
  10.     .height = 30
  11.     .text = "Click !"
  12.  
  13.  
  14. Public Sub MyButton_Click()

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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 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….
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
Doctor Watson is in the usergroup ‘Regular’
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.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
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.
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’

Doctor Watson said

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
/lang/new - Gambas Documentation

the examples you have not yet found are there.

Less speed more read my friend ;)
Online now: No Back to the top
1 guest and 0 members have just viewed this.