Create UI elements at runtime

DesktopButton is the base of Button1 / YourButton
if DesktopButton have property x,y,with,height your new class Button1 have it too.
Button1 in form designer is the class name / object name
var b as new Button1

if you sub class a Canvas Object you can add your own methods / features there
and you can also drag/drop it into form designer as example.
you can process events from the canvas in this sub class or for each instance in a window event where it was placed.

So Button1 is both a class name and a instance (or object) name?

I have tried this and in my Xojo version R3 this doesn’t work:

i think because it is not a normal class and it was dropped into this window1

if you create a new class and set super to DesktopButton
this works in a window

Var b As New Button1
b.Width = 50
b.Height = 50
b.Caption = "assadasd"
b.Visible = True
Self.AddControl b
2 Likes

ok I guess we were considering two different scenarios. I was referring to a button dropped onto a Window, while you a Button dropped in the navigator, outside of a Window ! Sorry for the confusion!

So I am convinced it’s a small inaccuracy of the inspector: in case of a dropped button into a Window, DesktopButton should be labeled as Class and not Super!

i was wrong, seems buttons in a window designer are just DesktopButtons
that have the debugger showed. it make sense because there was no change at this class.

1 Like

yes, the confusion arises from the naming of the field as Super, that has a different meaning for Window (and custom classes) and UI controls into a Window

1 Like

i agree

1 Like