[Gambas-user] Trying to create a form and add controls dynamically

Benoit Minisini gambas at ...2...
Sat Sep 27 16:36:16 CEST 2003


Le Mardi 23 Septembre 2003 23:52, Tim Auld a écrit :
> Hi there,
> I am trying to create a form in Gambas dynamically and programatically add
> controls to the new form.  Has anyone done this?  Would you have an example
> I could use?
>
> Regards,
>
> Tim
>

You just have to create controls exactly like any other objects. The first 
argument of the control constructor must be the parent control or form.

To create a form:

MyForm = NEW Form

And, for example, here is how to add controls in this form:

PRIVATE MyLabel AS Label
...
MyLabel = NEW Label(MyForm)
MyLabel.Move(10, 10, 120, 30)
MyLabel.Text = "Hello"
...

If you want event handlers, do that:

MyLabel = NEW Label(MyForm) AS "MyLabel"
...
PUBLIC SUB MyLabel_Click()
...
END

When you create a form in the IDE, the gambas compiler replace it by this kind 
of code, as if you have typed it by hand.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list