# Programatically add a control

**URL:** <https://forum.xojo.com/t/programatically-add-a-control/17376>\
**Category:** Getting Started\
**Created:** [June 19, 2014, 5:00am UTC](https://forum.xojo.com/t/programatically-add-a-control/17376 "2014-06-19T05:00:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamish\_Steiner](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/f9ae1b/32.png) [@Hamish\_Steiner](https://forum.xojo.com/u/Hamish_Steiner)\
**Post date:** [June 19, 2014, 5:00am UTC](https://forum.xojo.com/t/programatically-add-a-control/17376/1 "2014-06-19T05:00:09Z")

</div>

If I want to add a label dynamically to a window (desktop) I can find a good example.  
I think I have to do a containercontrol then add it to that.  
Is this the way to do it?  
Does anyone have a code snippet??

---

<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:** [June 19, 2014, 5:27am UTC](https://forum.xojo.com/t/programatically-add-a-control/17376/2 "2014-06-19T05:27:28Z")

</div>

For something like a label, I think a Control Set would be better than a ContainerControl. Put a label on the window, say, Label1. Select it and click the gear icon in the inspector. Make it Member Of -\> New Control Set. Now you can add a new Label1 to the window with code like:

```auto
dim l as Label = new Label1
l.Left = x
l.Top = y
l.Text = "New label"
```

---

<div class="post-metadata">

**Author:** ![Antonio\_Simone](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/b38774/32.png) [@Antonio\_Simone](https://forum.xojo.com/u/Antonio_Simone)\
**Post date:** [June 19, 2014, 5:38am UTC](https://forum.xojo.com/t/programatically-add-a-control/17376/3 "2014-06-19T05:38:27Z")

</div>

Hamish,  
I Agree with Tim, Control Set would be the better and more flexible option.

1. in addition to what Tim suggested you might create the label and set it to invisible (label1.visible =FALSE), then add programmatically:

```auto
dim nicelabel as label1
nicelabel = new label1
nicelabel.left = x
nicelabel.top=y
nicelabel.visible=TRUE

```

you also have a 2nd simpler option, if the case.  
So, if you just need one label, you can put it where you want on the window and then set the visible property to FALSE. When you need it to be shown , then set the label visible property to TRUE.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:16pm UTC](https://forum.xojo.com/t/programatically-add-a-control/17376/4 "2020-10-29T17:16:47Z")

</div>


