DrawInto should draw a control, right?

So, Tim and Ian, in the Layout Editor, I add a Canvas control, and embed in it a Container control. This way I can add scrollbars and use the Scroll method to slide the Canvas around and the Container control with it.
But, how to add a new control to the Container control, using code?
Lets say I need to add a TextField and a Check Box. And, later, lets say I invoke a command that adds a ComboBox to the Container control?
And, later on, another command would add it a DateTime Picker.
Is that possible?

If you add a Canvas to a window you can instantiate controls and add them to the cavas using EmbedWithin (no Container required). Add a scrollbar to the window and use it to scroll the canvas.

Container is good if you want a combination of controls that are fairly fixed although you can add as required using AddControl). The ContainerControl can then be added to other windows as required.

Talking about DateTime picker you are starting to sound like you are building a grid control with different column types and controls to enter data?

Actually, I’m creating a personal database to organize hundreds of texts that I have.
But, some texts include images, others include references to dates, etc.
So, I want to be able to create something flexible.
And, you mean I can, for example, create a new TextField object and EmbedWithin a Canvas?
But I need to have a TextField control (and set its visibility to False) somewhere in my layout to be able to instantiate it, right?
Or can I simply create a new one, in code, with…

Var t_field as New TextField

and then place it in the Canvas with…

t_field.EmbedWithin(my_canvas)

??

It would appear not. EmbedWithin only seems to work with ContainerControl.

Which would suggest I was on the right lines with adding a Container to the canvas. You add controls to the Container and Scroll the canvas it contained within.

I’m not sure how scalable such as interface would be. If there are 1,000 of messages then I think this isn’t going to work. Generally, you don’t want 100s of controls on a window all at the same time.

So, I just need to embed the Container control inside the Canvas, and do…

Var t_field as New TextField
t_field.EmbedWithin(my_Container)
Var t_field as New TextField
' set any properties of t_field here.
my_Container.AddControl(t_field)

I was able to add a ContainerControl to my project, embed an instance of it to my Canvas, but I get this error:

Type “Container1.Container1” has no member named “AddControl”
canvas_container.AddControl(t_field)

Where is your code. If it is in the window then you should just need Container1.AddControl. The window doesn’t care if the container is within a Canvas. You also have to use the new Desktop versions of the controls. You can’t use:

Var t_field As New TextField
Container11.AddControl(t_field)

you have to use

Var t_field As New DesktopTextField
Container11.AddControl(t_field)
  • Add a ContainerControl to a project
  • Add a Canvas to a Window
  • Add an instance of the ContainerControl to the Canvas
  • Double click the canvas and add the following code to the Open event:
Var t_field As New DesktopTextField
t_field.top = 29
t_field.Left = 29
t_field.Width = 80
t_field.Height = 22
t_field.BackgroundColor = Color.White
t_field.HasBorder = True
t_field.Text = "1234" ' Important

Container11.AddControl(t_field)

It doesn’t seem to work if there is no content to the control (see Important)

I still get the error:

This item does not exist
my_container.AddControl(t_field)

Is it a DesktopContainer? It needs to be, rather than the API1 Container. If so just change the super to DesktopContainer.

Also, look out for Class names and instance names. You add a DesktopContainer to your project. Say Container1.

You then add an instance of that to your window (within the canvas). That would likely end up called Container11 (the first instance of Container1 on the Window).

You don’t add to the class (that you added to your project). You add to the instance that you put on your window.

Screenshot 2022-10-03 at 00.30.17

I did all that, and although I don’t get any error now, I still get no TextField added to the DesktopContainer.
Also, I had to download the 2022 version of Xojo (that will not allow me to build an app) to be able to do this.
And I can only build apps with the 2021 version (the one that my boss bought and has no intentions to upgrade :frowning: )
So, it is impossible to add controls dynamically in versions prior 2022 ?

Have a look at this:

@Christian_Schmitz’ scrolling container list is very easy to use, and doesn’t actually require any MBS plugins, although I’m not sure if the example project is available for download anywhere.

Note it does show some unpleasant visual artifacts under Windows when scrolling.

Thank you, Julia.
This is for a personal project, so I will only have to used it on Mac OS.
However, I need a way to create controls in code, not already placed controls inside a container, that I will scroll.
I find it strange that it isn’t easier to create GUI elements in code.
When I code plugins in python for Cinema 4D, creating the dialogs in code is pretty straightforward. Why is it so complex in Xojo?

In the Examples folder, I guess I found something that my help me, somehow.
It is the DownloadContainer example.
I may have to change a bit the way I was planing to do what I wanted, but I think I may be able to do what I need.
Thank you all for the help.

There was a big change from API1 to API2. In API1, the only ways to create a control on the fly was
a) Have one already on the window and make it a control set.
b) Have a ContainerControl created in the IDE and Embed it at runtime.

In API2, they added AddControl. However, to use that you must be using API2 windows and controls. Namely, DesktopWindow and DesktopTextField.

API2 was introduced in 2021r3.

All that said, From what you have described, using ContainerControls and embedding them in a Canvas is your best approach. The drawback is that with API1, you have to predefine the containers. API2 allows you to define them on the fly.

If your boss bought the 2021 version, you get a full year of updates, so you may be able to get a newer version free.

Thank you so much, Tim.
I will tell my boss.
In the meanwhile, I think that having a ContainerControl created in the IDA and embedding it at runtime is actually my best choice, because I want each control to be a bit more complex (have a background, a title, maybe an icon, besides that control itself).
Thank you all.

Probably not needed…

Go there and look at the dates:
https://xojo.com/account/licenses/manage.php

If your current license is still valid at Xojo 2022r2 release date, you only have to download it and run!

I have to ask the service desk guys. Thank you.

You should know that Drawinto does not draw the background.