Desktop AddControl

Can someone point me in the direction of an example app using the AddControl capability in Desktop? I have the code


where MyButton1 is a simple DesktopButton. It compiles fine and seems to run but where is the new control? How do I reference it to set its location and appearance, to say nothing about handling its events?

What about:

MyButton1.Top  = 30
MyButton1.Left = 75

and I imagine you can use AddHandler to add events to it.

Can you pause the app in the debugger and examine its properties?

Because the controls aren’t based on anything made at design time, the problem is that you need to assign the width and height, otherwise the control is initialised with 0’s and you can’t see it, you keep a reference to it in any other way you keep references to things, an array/dictionary etc.

Xojo will be coming out with an English voice over of Javier’s demo soon (as they more often than not do), but you can google translate the page and see how to use it here as well as check the video AddControl: Añadir controles de UI en tiempo de ejecución - YouTube and follow the bitly link in the description to download a demo.

As the controls aren’t based on anything “real”, they have no meaningful defaults, I’ve yet to fix the background color of added textfield’s as I’ve only played with it for a few minutes while reporting a bug but it was coming out black in windows dark mode as apposed the “correct” background color of a textfield added at design time. Plenty of room for improvement, but its a start and has been sorely missed that you couldn’t just create controls on the fly, they had to be based on something.

Thanks, Julian. I’ll take a look at the web page (through Google Translate) and see if it makes sense to me.

This is what I was hinting at.

Thanks again, Julian. That article was exactly what I needed. It clarified the issue.

As it turns out, I had already used the methodology, albeit not the specific command, when dynamically adding container controls to to a window.

1 Like