<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Control Set &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/control-set/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Thu, 21 Apr 2022 00:11:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Desktop: Adding Controls at Runtime</title>
		<link>https://blog.xojo.com/2022/01/07/desktop-adding-controls-at-runtime/</link>
		
		<dc:creator><![CDATA[Xojo]]></dc:creator>
		<pubDate>Fri, 07 Jan 2022 21:58:01 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Control Set]]></category>
		<category><![CDATA[Multi-Platform Development]]></category>
		<category><![CDATA[Xojo API 2.0]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9876</guid>

					<description><![CDATA[If you have been using Xojo, you may be used to adding Controls at runtime using Control Sets. You  may not know it but beginning with Xojo 2021r3, there is a better way. Using the new Desktop Controls introduced in  Xojo 2021r3, you can add Controls to a DesktopWindow at runtime using AddControl, just like you do with Xojo Mobile and Web projects.]]></description>
										<content:encoded><![CDATA[
<p>If you have been using Xojo, you may be used to adding controls at runtime using <a href="https://documentation.xojo.com/topics/user_interface/desktop/desktop_controls/control_sets.html">Control Sets</a>. You may not know it but beginning with Xojo 2021r3, there is a better way. Using the <a href="https://blog.xojo.com/2021/11/18/new-desktop-controls/">new Desktop Controls</a> introduced in  Xojo 2021r3, you can add controls to a DesktopWindow at runtime using AddControl, just like you do with Xojo <a href="https://documentation.xojo.com/api/user_interface/mobile/mobilescreen.html">Mobile</a> and <a href="https://documentation.xojo.com/api/user_interface/web/webpage.html">Web</a> projects.</p>



<p>Once you start using AddControl in your new Desktop projects (we definitely recommend that!) you&#8217;ll see it&#8217;s more convenient, plus you aren&#8217;t required to have a control to be used as a template already on the Window. </p>



<p>Related: Read &#8220;Simplified: <a href="https://blog.xojo.com/2022/01/21/simplified-adding-user-interface-controls-at-runtime/">Adding User Interface Controls at Runtime</a>&#8220;</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Add User Interface Controls at Runtime</title>
		<link>https://blog.xojo.com/2018/01/26/how-to-add-ui-controls-at-runtime/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Fri, 26 Jan 2018 07:10:59 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[AprendeXojo]]></category>
		<category><![CDATA[Control Set]]></category>
		<category><![CDATA[User Interface]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=3770</guid>

					<description><![CDATA[How can I add new UI controls to the Window at runtime? And if you are considering this too, then the good news is that the answer is more simple than you probably expect… sitting right there on the Inspector Panel under the Attributes tab. Yes, this is all about the Control Set!]]></description>
										<content:encoded><![CDATA[<p>Admit it &#8211; this is one of those questions that, sooner or later, arise to every Xojo newcomer: How can I add new UI controls to the Window at runtime? And if you are considering this too, then the good news is that the answer is more simple than you probably expect… sitting right there on the Inspector under the Attributes tab. Yes, this is all about the Control Set!<span id="more-3770"></span></p>
<p>Before we put our hands on it, let&#8217;s make some things clear about the <a href="http://developer.xojo.com/userguide/desktop-control-sets">Control Set</a>:</p>
<ul>
<li>You can use this feature to dynamically create any kind of control based on the <a href="http://developer.xojo.com/userguide/desktop-control-sets"><b>RectControl</b></a> class.</li>
<li>You can use Control Sets on <b>Desktop</b> and <b>Web</b> projects (although web projects cannot use Control Sets to dynamically create controls at runtime).</li>
<li>You cannot create Control Sets for Container Controls.</li>
<li>The Control Sets may seem like Arrays, because you will use an <b>index</b> to refer every instance from the same Control Set, but they are not. So, don&#8217;t think about them in that way.</li>
<li>All of the instances of the Control Set will share the same <b>Event Handlers</b>, so you will have to use the additional <b>index</b> argument, passed to the Event Handler, in order to identify over which instance are you handling.</li>
</ul>
<p>But, how can we create one of these Control Set after all? Well, we just need to put any control we want to use as a <em>clonation template</em> on the Window, even if it is placed outside the visible limits of the Window itself. Then, and with the control still selected, you just have to push on the attributes button (the one with the image of a gearwheel) on the Inspector, selecting the <code class="inlinecode">New Control Set</code> option from the <code class="inlinecode">Member Of</code> entry under the <code class="inlinecode">Control Set</code> Section.</p>
<blockquote><p><b>Tip</b>: If you change the name of the Control used to create a Control Set, then you will have to recreate the Control Set, so rename the template Control in the first place!</p></blockquote>
<p>Once you have created the new Control Set, you will see that the first instance of the Control Set is assigned the <b>index</b> number 0; succesive instances will have their index increassed by one, both the ones you may add to the Window (not what we want to do in this case), and those created at runtime (what we want to do).</p>
<p>Now, probably you will want to change the <code class="inlinecode">Visibility</code> Property to <code class="inlinecode">False</code> on this first cloning template control, so it will not be visible to the users of the app no matter the resizing of the containing Window.</p>
<p>Once our cloning control is all set, it’s time to reveal all the code we will need in order to create new instances of the control at run time. Let’s indicate that we have used as cloning template Control a PushButton and that we have named it <code class="inlinecode">btClon</code>. Then, we just need this to create a new instance, making it visible on the Window:</p>
<pre>Dim newInstance as PushButton = new btClon
newInstance.visible = true</pre>
<p>Remember that every <b>UI</b> component is based on (<em>inherits from</em>) the RectControl class, so you also can do this:</p>
<pre>Dim newInstance as RectControl = new btClon
PushButton(newinstance).visible = true</pre>
<p>As you can see, the difference is that in this case you have to <a href="http://developer.xojo.com/userguide/advanced-oop-features"><b>Cast</b></a> the generic RectControl instance to the PushButton class in order for you to use and access all the PushButton methods and properties from code.</p>
<p>Why should you use this formula, then? Well, if you are thinking about creating several Types of UI components at runtime, then you will probably prefer to create them using a more generic RectControl variable or reference (maybe a RectControl Array containing all of your dinamically created controls).</p>
<p>As you may expect, the new instances created from a template will have the same properties, events and methods the template control has, with the difference that it will also inherit the clone properties values. This is why once a new instance is created we need to make it visible again and you will want to change other properties too, for example the <code class="inlinecode">Caption</code> and the <code class="inlinecode">Left</code> and <code class="inlinecode">Top</code> properties among others.</p>
<h2>Modifying the Z axis order of the Control</h2>
<p>We already know that every new created instance of the Control Set gets its index increased by one. What you have to know is that every new instance is above the previous one on the Z axis of the Window. I mean, if the control with the <code class="inlinecode">Index</code> set to 2 partially overlays the position of the control with the <code class="inlinecode">Index</code> 1, then the first one will overlay the second. What if you decide to have a control with a low index value above the others?</p>
<p>Currently there is no easy way we can dynamically change the Z order of a control to any desired value, but there is an easy way we can move any control to the foreground, so it can stay in front of all of them!</p>
<p>Let’s say that we have our cloned control with the <code class="inlinecode">Index</code> 1 and want to show it in the foreground, with the highest possible value in the Z axis. All we have to do is assign it to another RectControl as its <code class="inlinecode">parent</code> property value, for example the control we are using as cloning template. Once done, we will assign the Window again as the <code class="inlinecode">parent</code> property value of the control. The code could be something similar to this:</p>
<pre>btClon(2).parent = btClon(0)
btClon(2).parent = Window1 //Or Self or Me, depending where you place the code</pre>
<p>In conclusion, as you can see, the creation of UI controls at runtime is something really easy to do in Xojo! But what if you need to dynamically add a group or layout of control at runtime? Well, in that case don&#8217;t forget about the <a href="https://blog.xojo.com/2017/04/26/containercontrol-making-a-multiplatform-search-field/" target="_blank" rel="noopener">ContainerControls</a>!</p>
<p><em>Javier Rodri­guez has been the Xojo Spanish Evangelist since 2008, he’s also a Developer, Consultant and Trainer who has be using Xojo since 1998. He manages <a href="http://www.aprendexojo.com">AprendeXojo.com</a> and is the developer behind the GuancheMOS plug-in for Xojo Developers and the Snippery app, among others.</em></p>
<p>*<a href="https://www.aprendexojo.com/2018/01/anadir-controles-de-ui-en-tiempo-de-ejecucion/">Read this post in Spanish</a></p>
<p>*<a href="https://www.youtube.com/watch?v=9NAap4Ipmnc">Watch the video in Spanish</a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
