# DrawInto should draw a control, right?

**URL:** <https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520>\
**Category:** General\
**Created:** [October 2, 2022, 6:23pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520 "2022-10-02T18:23:04Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 9:44pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/21 "2022-10-02T21:44:56Z")

</div>

> [@TimStreater](#):
>
> I’m suggesting you use EmbedWithin rather than AddControl

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?

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [October 2, 2022, 9:48pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/22 "2022-10-02T21:48:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 9:55pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/23 "2022-10-02T21:55:40Z")

</div>

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…

```auto
Var t_field as New TextField

```

and then place it in the Canvas with…

```auto
t_field.EmbedWithin(my_canvas)

```

??

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [October 2, 2022, 10:03pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/24 "2022-10-02T22:03:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 10:07pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/25 "2022-10-02T22:07:08Z")

</div>

> [@Ian\_Kennedy](#):
>
> It would appear not. EmbedWithin only seems to work with ContainerControl.

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

```auto
Var t_field as New TextField
t_field.EmbedWithin(my_Container)

```

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [October 2, 2022, 10:08pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/26 "2022-10-02T22:08:42Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 10:24pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/27 "2022-10-02T22:24:39Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [October 2, 2022, 10:56pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/28 "2022-10-02T22:56:41Z")

</div>

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:

```auto
Var t_field As New TextField
Container11.AddControl(t_field)

```

you have to use

```auto
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:

```auto
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)

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 11:16pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/29 "2022-10-02T23:16:38Z")

</div>

I still get the error:

This item does not exist  
my\_container.AddControl(t\_field)

---

<div class="post-metadata">

**Author:** ![Ian\_Kennedy](https://forum.xojo.com/user_avatar/forum.xojo.com/ian_kennedy/32/6860_2.png) [@Ian\_Kennedy](https://forum.xojo.com/u/Ian_Kennedy)\
**Post date:** [October 2, 2022, 11:18pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/30 "2022-10-02T23:18:34Z")

</div>

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](https://forum.xojo.com/uploads/default/original/2X/d/d740d25f102b8cab65121cc5f92ba620d6badcac.png)

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 11:36pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/31 "2022-10-02T23:36:36Z")

</div>

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 ☹ )  
So, it is impossible to add controls dynamically in versions prior 2022 ?

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [October 2, 2022, 11:48pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/32 "2022-10-02T23:48:46Z")

</div>

Have a look at this:

> [@Smooth scrolling list control with ContainerControls](https://forum.xojo.com/t/smooth-scrolling-list-control-with-containercontrols/63489):
>
> Recently I implemented [NSCollectionViewControlMBS](https://www.monkeybreadsoftware.net/control-nscollectionviewcontrolmbs.shtml) control for Xojo to have a grid of items based on container controls. But a few days ago we had the need for having just a few containers to scroll on a window in Xojo. You may start to implement this in Xojo with a scrollbar and then move in the ValueChanged the containers up/down as needed. Quickly you may realize you need a wrapping container to clip the scrolling ones properly. But if you loop over containers and change their Top property to …

@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.

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 2, 2022, 11:59pm UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/33 "2022-10-02T23:59:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 3, 2022, 12:19am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/34 "2022-10-03T00:19:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [October 3, 2022, 1:05am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/35 "2022-10-03T01:05:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [October 3, 2022, 6:08am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/36 "2022-10-03T06:08:56Z")

</div>

> [@Rui\_Batista1](#):
>
> And I can only build apps with the 2021 version

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.

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 3, 2022, 9:38am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/37 "2022-10-03T09:38:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [October 3, 2022, 9:56am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/38 "2022-10-03T09:56:08Z")

</div>

> [@Rui\_Batista1](#):
>
> I will tell my boss.

Probably not needed…

Go there and look at the dates:  
[https://xojo.com/account/licenses/manage.php](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!

---

<div class="post-metadata">

**Author:** ![Rui\_Batista1](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Rui\_Batista1](https://forum.xojo.com/u/Rui_Batista1)\
**Post date:** [October 3, 2022, 10:16am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/39 "2022-10-03T10:16:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [October 3, 2022, 10:55am UTC](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520/40 "2022-10-03T10:55:59Z")

</div>

> [@Rui\_Batista1](#):
>
> have a background

You should know that Drawinto does not draw the background.

[Previous page](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520.md?page=1)

[Next page](https://forum.xojo.com/t/drawinto-should-draw-a-control-right/72520.md?page=3)
