<?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>Container &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/container/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Mon, 18 Aug 2025 20:38:46 +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>Cosmic Trader: A Game Built with Xojo Web</title>
		<link>https://blog.xojo.com/2024/09/17/cosmic-trader-a-game-built-with-xojo-web/</link>
		
		<dc:creator><![CDATA[Ricardo Cruz]]></dc:creator>
		<pubDate>Tue, 17 Sep 2024 20:09:12 +0000</pubDate>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[WebListBox]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=13618</guid>

					<description><![CDATA[I truly enjoy creating things with Xojo. This time, I built a little game with Xojo Web just to see if it was possible. In&#8230;]]></description>
										<content:encoded><![CDATA[
<p>I truly enjoy creating things with Xojo. This time, I built a little game with Xojo Web just to see if it was possible. In this post, I will talk about what I liked and what I had difficulties with while programming it.</p>



<p>The reason to create this kind of project, as the maintainer of the Xojo Web framework, is to find pain points and bugs in larger projects, as the issue reports I normally work with are very specific sample projects demonstrating a bug. The next Xojo release, 2024r3, will come with some bug fixes I found while building Cosmic Trader.</p>



<h2 class="wp-block-heading">Final Result</h2>



<p>Let&#8217;s begin at the end. Give the game a try and then come back to this blog post. It&#8217;s a very simple space trading game, don&#8217;t expect too much from it, but I hope you enjoy it.</p>



<p>It can be played from the following URL:<br><a href="https://cosmictrader.rcruz.es" target="_blank" rel="noreferrer noopener nofollow">https://cosmictrader.rcruz.es</a></p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="625" src="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.16-1024x625.png" alt="" class="wp-image-13619" srcset="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.16-1024x625.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.16-300x183.png 300w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.16-768x469.png 768w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.16.png 1252w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="625" src="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.32-1024x625.png" alt="" class="wp-image-13620" srcset="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.32-1024x625.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.32-300x183.png 300w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.32-768x469.png 768w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-8.53.32.png 1252w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">The Challenge</h2>



<p>Create a simple game using Xojo Web, without writing a line of JavaScript, or even using the Web SDK.</p>



<p>In addition, while all this could be just a couple of WebListBox and WebButton controls, I really wanted this game to look like an actual game. As you can see in the screenshots, unless you check the code, nobody will notice (or care!) it&#8217;s a Xojo Web application.</p>



<p>As you can imagine, Xojo Web was not created with the idea of building web based games. In order to make it easier for the developer, everything is processed server side: When you press a button, the browser will send a notification to the server, your code written in Xojo will be executed and, finally, the response will be sent back to the browser.</p>



<p>That&#8217;s the known knowns. I knew the latency would be a problem, but I&#8217;ve found more.</p>



<h2 class="wp-block-heading">What I&#8217;ve Enjoyed</h2>



<p>Implementing the first prototype was really easy using the tools Xojo Web offers. For example, in the prototype, instead of the custom popover I ended up building for buying and selling, I just used some contextual menus:</p>



<figure class="wp-block-video"><video height="732" style="aspect-ratio: 1072 / 732;" width="1072" controls src="https://blog.xojo.com/wp-content/uploads/2024/09/cosmic-trader-early-prototype.mp4"></video></figure>



<p>You can go very far and prototype your idea very quickly this way. This helped me to deploy and share the game with a few friends and gather some initial feedback.</p>



<p>Once you have the game mechanics, you can iterate as much as you want until the game is ready. The welcome screen with the game logo wasn&#8217;t added until very late. Just so you can compare, this is how the current version looks:</p>



<figure class="wp-block-video"><video height="598" style="aspect-ratio: 946 / 598;" width="946" controls src="https://blog.xojo.com/wp-content/uploads/2024/09/cosmic-trader-current-version.mp4"></video></figure>



<p>Much better! <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f60e.png" alt="😎" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p>I&#8217;ve really enjoyed being able to use Containers for building custom controls and reusing them. Also, being able to just drop some images into the IDE and assign them to image viewers is very pleasant.</p>



<p>From the IDE preview, it&#8217;s deadly easy to identify where my ship entity is, click on it, then edit the code if needed:</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="720" src="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-9.32.10-1024x720.png" alt="" class="wp-image-13624" srcset="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-9.32.10-1024x720.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-9.32.10-300x211.png 300w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-9.32.10-768x540.png 768w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-9.32.10-1536x1080.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-9.32.10-2048x1440.png 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Navigating through the project is a joy compared to jumping through piles of code in plain text files.</p>



<p>I&#8217;ve also found having Control Sets useful, allowing me to implement the Pressed event just once for all the planets, for example.</p>



<h2 class="wp-block-heading">Roadblocks and How I Handled Them</h2>



<p>That said, I found some difficulties. All of them were due the nature of web projects. When you travel from one planet to another, you will hear an engine sound. It would be much (much!) easier to know when I should stop the sound in a Desktop or a Mobile project.</p>



<p>Having to deal with latency means I had to use a timer and guess more or less how many milliseconds is reasonable before stopping the sound. Using the same amount of time as the animation would cause the sound to continue playing after the ship had arrived at its destination, again due the latency.</p>



<p>Where I spent most of the time was optimizing the images. Specifically, delivering the images. When you play the game locally, everything works pretty fast. I found this flickering issue once I deployed the game for the first time using the custom popovers:</p>



<figure class="wp-block-video"><video height="670" style="aspect-ratio: 1276 / 670;" width="1276" controls src="https://blog.xojo.com/wp-content/uploads/2024/09/cosmic-trader-flickering-issue.mp4"></video></figure>



<p>This is something that you just don&#8217;t need to think about with the typical database application you normally build with Xojo Web. But if you build a lot of images on the fly, it will mean the browser will have to download them again and again.</p>



<p>In order to optimize it, instead of using a WebImageViewer.Image property, you could store WebImage instances. Using WebImageViewer.URL pointing to the WebImage.URL property of those instances will make the browser first check if it has downloaded that URL before. If so, bingo! It will reuse the image without having to re-download it again.</p>



<p>If you go back to the game, cache is the reason behind the &#8220;New Game&#8221; button, from the welcome screen, and the &#8220;Sell Everything&#8221; button having the same width. It wasn&#8217;t a coincidence, that means a browser cache hit.</p>



<p>Last but not least, when I shared the URL with some friends, they told me it didn&#8217;t look great on mobile. So I had to change the stats a bit so they fit in a mobile screen. While in this case it wasn&#8217;t a big deal, at Xojo we know making responsive web applications must be easier, and we will improve the workflow in future releases.</p>



<p>It would be much easier to use the Web SDK for some of those controls. If I was creating a game seriously, I&#8217;d 100% personally prefer creating some custom controls to allow some code to run on the browser side, using the Web SDK with JavaScript or TypeScript, to avoid dealing with latency or round-trips.</p>



<h2 class="wp-block-heading">Using AI for Creativity</h2>



<p>I personally don&#8217;t find any joy using AI for coding. I always end up frustrated by how it hallucinates and keep proposing, very confidently, things that just don&#8217;t exist. I understand some might like it but, in the end, I just like coding.</p>



<p>But for a second brain and helping me with (my lack of) creativity&#8230; oh boy, that&#8217;s another story. The game idea came from a conversation with Claude AI. Initially, it came up with tons of features and ideas that would require me (and a team of another 100 people) to work on it for several years. I kept asking it to simplify it until I felt it was approachable:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="415" src="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-10.19.09-1024x415.png" alt="" class="wp-image-13625" srcset="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-10.19.09-1024x415.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-10.19.09-300x121.png 300w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-10.19.09-768x311.png 768w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-10.19.09-1536x622.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-09-16-a-las-10.19.09.png 1768w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>After implementing the game mechanics, I felt the game didn&#8217;t make any sense. I mean, why 30 turns exactly? Why 5 planets? Why can&#8217;t I go somewhere else to trade? Why do I have to trade at all?&#8230; While it is still fiction, the AI wrote a reasonable background story that added some depth to the game. That&#8217;s what you will be reading when playing Cosmic Trader.</p>



<p>No spoilers, but there are still a few features and game mechanics, recommended by the AI, that I left for future releases.</p>



<p>While working on this game, I even had a little ant invasion at home. The AI came up with a multiplayer ant colony simulator game idea that I will probably never implement, but who knows!</p>



<p>For the logo, I had some spare credits to use with DreamStudio. I had to retouch it using Affinity Photo, but that&#8217;s it:</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="256" src="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-07-30-a-las-12.32.26-1024x256.png" alt="" class="wp-image-13626" srcset="https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-07-30-a-las-12.32.26-1024x256.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-07-30-a-las-12.32.26-300x75.png 300w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-07-30-a-las-12.32.26-768x192.png 768w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-07-30-a-las-12.32.26-1536x385.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/09/Captura-de-pantalla-2024-07-30-a-las-12.32.26-2048x513.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>All in all, and while a team of real humans will always be much better, I reckon AI helped me a lot with this experiment.</p>



<h2 class="wp-block-heading">Credits and Acknowledgements</h2>



<p>I could focus on building the game thanks to using the <a href="https://kenney.nl" target="_blank" rel="noreferrer noopener nofollow">Kenney game assets</a>. The background music author is <a href="https://pixabay.com/users/the_mountain-3616498/" target="_blank" rel="noreferrer noopener nofollow">Dmitrii Kolesnikov</a>, make sure to check his profile.</p>



<p>Thanks to Claude for being my second brain for this project. And, of course, thanks to Xojo. It wouldn&#8217;t be as fun without it.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>I enjoyed building this project a lot. I learned things, and I fixed some bugs I found. Did you know you couldn&#8217;t add a WebStyle CSS transition without adding other styles? Me neither, but it will be fixed in Xojo 2024r3.</p>



<p>Happy coding!</p>



<p><em>Ricardo has always been curious about how things work. Growing up surrounded by computers</em> he became interested in <em>web technologies in the dial-up connections era. Xojo has been his secret weapon and language of preference since 2018. When he’s not online, chances are he will be scuba diving … or crocheting amigurumis. Find Ricardo on Twitter <a href="https://web.archive.org/web/20220805000833/https://www.twitter.com/piradoiv" target="_blank" rel="noreferrer noopener">@piradoiv</a>.</em></p>
]]></content:encoded>
					
		
		<enclosure url="https://blog.xojo.com/wp-content/uploads/2024/09/cosmic-trader-early-prototype.mp4" length="970692" type="video/mp4" />
<enclosure url="https://blog.xojo.com/wp-content/uploads/2024/09/cosmic-trader-current-version.mp4" length="776410" type="video/mp4" />
<enclosure url="https://blog.xojo.com/wp-content/uploads/2024/09/cosmic-trader-flickering-issue.mp4" length="295405" type="video/mp4" />

			</item>
		<item>
		<title>Simplified: Adding User Interface Controls at Runtime</title>
		<link>https://blog.xojo.com/2022/01/21/simplified-adding-user-interface-controls-at-runtime/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Fri, 21 Jan 2022 15:07:22 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Container]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Xojo API 2.0]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=9793</guid>

					<description><![CDATA[The process of adding new controls to windows (or containers) at runtime has been greatly simplified. Instead of having to deal with control arrays, when you use Xojo 2021r3 or later you can call the new AddControl method on the DesktopWindow (or DesktopContainer) where you want to add the new control. ]]></description>
										<content:encoded><![CDATA[
<p>The process of adding new controls to windows (or containers) at runtime has been greatly simplified. Instead of having to deal with control arrays, when you use Xojo 2021r3 or later you can call the new AddControl method on the DesktopWindow (or DesktopContainer) where you want to add the new control. Continue reading and I will show you how!</p>



<span id="more-9793"></span>



<p>The new AddControl method on <a href="https://documentation.xojo.com/api/user_interface/desktop/desktopwindow.html">DesktopWindow</a> and <a href="https://documentation.xojo.com/api/user_interface/desktop/desktopcontainer.html">DesktopContainer</a> accepts any <a href="https://documentation.xojo.com/api/user_interface/desktop/desktopuicontrol.html">DesktopUIControl</a> instance you want to add to a window or container.</p>



<p>To make the new DesktopUIControl instance really visible in the target window or container, you&#8217;ll need to set some basic properties; specifically the desired width and height values for the new instance control and also the left and top coordinate values where you expect the control to be added. These values are relative to the left/top corner of the target window/container, so a value of top = 0 and left = 0 means to add the control at the top/left corner of the target window itself.</p>



<p>In order to see how this works, this example creates a Desktop project that includes multiple DesktopButton instances at runtime while also removing them from the target DesktopContainer (calling the Close method on the instance to do that). Plus we&#8217;ll make them adjust as the size of the Container changes like you see in this example below.</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="618" height="442" src="https://blog.xojo.com/wp-content/uploads/2021/12/AddControl.gif" alt="" class="wp-image-9796"/></figure></div>



<h3 class="wp-block-heading">1. Creating the Base Container</h3>



<p>Open Xojo and create a new Desktop project. Double click on the Container in the Library so it is added to the Navigator in the IDE. Use the Inspector panel to change the following properties:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> <code>BaseContainer</code></li></ul>



<p>Add a new property to the BaseContainer subclass in the Navigator (use the contextual menu for that), setting the following values in the Inspector panel:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> <code>Controls()</code></li><li><strong>Type:</strong> <code>DesktopUIControl</code></li><li><strong>Scope:</strong> <code>Public</code></li></ul>



<h3 class="wp-block-heading">2. Adding New Controls to the BaseContainer</h3>



<p>We are going to need some Methods in the BaseContainer, starting with the one responsible for adding new DesktopButton instances. Add a new Method setting the following values in the associated Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> <code>AddNewControl</code></li><li><strong>Scope:</strong> <code>Public</code></li></ul>



<p>Write the following snippet of code in the associated Code Editor for the Method:</p>



<pre class="wp-block-preformatted">// Setting static values for the new Button instances
// Width and Name values
Static cWidth As Integer = 40
Static cInitialName As String = "ControlName"

// Initial X and Y coordinates for the control instance
Var startX As Integer = If(Controls.Count = 0, 20, Controls(Controls.LastIndex).Left + cWidth + 20)
Var startY As Integer = If(Controls.Count = 0, 20, Controls(Controls.LastIndex).Top)

// We need to adjust the X/Y coordinates if the control
// exceeds the available BaseContainer width
If startX + cWidth &gt; Me.Width Then
  startX = 20
  startY = startY + Controls(Controls.LastIndex).Height + 20
End If

// Creating the new DesktopButton instance to be added
// and setting the expected values so it is visible
// at the desired size and position.
Var nControl As New DesktopButton
Var idxNumber As Integer = Controls.LastIndex + 1
nControl.Name = cInitialName + idxNumber.ToString
nControl.Caption = idxNumber.ToString
nControl.Left = startX
nControl.Top = startY
nControl.Width = cWidth

// On macOS we get the default height for free
// this is not the case on Windows
#If TargetWindows Then
  nControl.Height = 22
#EndIf

// We set the method to be called by the instance
// when the user presses the button
// so we can catch it and forward it to the
// BaseControl instance
AddHandler nControl.Pressed, AddressOf ControlActionCallback

// Adding the new control instance to the array
controls.Add(nControl)

// …and adding it to the BaseContainer
// calling the new AddControl method for that
Me.AddControl(nControl)</pre>



<p>As you can see, we are using the AddHandler method to substitute the original Event fired by the control with our own Method; so let&#8217;s create that. Add a new Method to BaseContainer using the following values in the Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> <code>ControlActionCallback</code></li><li><strong>Parameters:</strong> <code>tControl As DesktopUIControl</code></li><li><strong>Scope:</strong> <code>Public</code></li></ul>



<p>And write this line of code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">RaiseEvent ControlPressed(tControl)</pre>



<h3 class="wp-block-heading">3. Removing Controls From the BaseContainer</h3>



<p>The third and last method we need to add to our BaseContainer subclass is the one responsible of removing the last added control; add a new method to the BaseContainer subclass using the following values:</p>



<ul class="wp-block-list"><li><strong>Method Name:</strong> <code>RemoveLastControl</code></li><li><strong>Scope:</strong> <code>Public</code></li></ul>



<p>And write the following snippet of code in the associated Code Editor for the Method:</p>



<pre class="wp-block-preformatted">If Controls.LastIndex &lt;&gt; -1 Then

  Var tControl As DesktopUIControl = Controls.Pop

  // We need to remove the callback method from the original
  // Pressed event on the instance
  RemoveHandler DesktopButton(tControl).Pressed, AddressOf ControlActionCallback

  // Closing the control instance so it is removed from the
  // containing BaseControl
  tControl.Close

End If</pre>



<h3 class="wp-block-heading">4. Forwarding Events</h3>



<p>Because we are forwarding the received Pressed event from the DesktopButton to the ControlActionCallback method, and it is raising the ControlPressed method passing along the received instance, we need to define that Event in our BaseContainer subclass using the following values in the associated Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Event Name:</strong> <code>ControlPressed</code></li><li><strong>Parameters:</strong> <code>tControl As DesktopUIControl</code></li></ul>



<h3 class="wp-block-heading">5. Reacting to Resizing</h3>



<p>We want our BaseContainer to react to changes in its width and/or height, so it has the chance to change the layout (position) of the controls added to it. With the BaseContainer selected in the Navigator, add the Resizing Event and type the following code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">#Pragma DisableBackgroundTasks
#Pragma DisableBoundsChecking

Var startX As Integer = 20
Var startY As Integer = 20

Var lastIndex As Integer = Controls.LastIndex
Var tControl As DesktopUIControl

For n As Integer = 0 To lastIndex

  tControl = Controls(n)

  If n &lt;&gt; 0 Then startX = Controls(n - 1).Left + Controls(n - 1).Width + 20

  If startX &gt; Me.Width - tControl.Width Then
    startx = 20
    If n &lt;&gt; 0 Then startY = startY + tControl.Height + 20
  End If

  tControl.Left = startX
  tControl.top = startY

Next n</pre>



<h3 class="wp-block-heading">6. Designing the User Interface</h3>



<p>Select the Window1 window in the Navigator so it is displayed in the Layout Editor. Next, drag a Button from the Library and place it at the top/left corner leaving the expected margins recommended by the Layout Guides.</p>



<p>With the just added button still selected, change the following values in the associated Inspector Panel:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> <code>AddControlButton</code></li><li><strong>Caption:</strong> &#8220;Add Control&#8221;</li></ul>



<p>Add the Pressed Event to the button and type the following line of code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">BaseContainer1.AddNewControl</pre>



<p>Add a second button and place it just below the previous one. Use the associated Inspector Panel to set the following values:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> <code>RemoveControlButton</code></li><li><strong>Locking:</strong> Left and Top locks closed</li><li><strong>Caption:</strong> &#8220;Remove Control&#8221;</li></ul>



<p>Use the resizing handlers on the control to make its width enough to display the Caption properly.</p>



<p>Add the Pressed Event to just added button and type the following line of code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">BaseContainer1.RemoveLastControl</pre>



<p>Add a Label from the Library and place it to the right of the first button. Use the Inspector Panel to set the following values:</p>



<ul class="wp-block-list"><li><strong>Locking:</strong> Left and Top locks closed</li><li><strong>Text:</strong> &#8220;Control Pressed:&#8221;</li></ul>



<p>Use the resizing handlers on the control to make its width enough to display the Text properly.</p>



<p>Add a second Label and place it to the right of the previous one, using the Inspector Panel to set the following values:</p>



<ul class="wp-block-list"><li><strong>Name:</strong> <code>ControlPressedName</code></li><li><strong>Locking:</strong> Left and Top locks closed</li><li><strong>Text:</strong> &#8220;&#8221;</li></ul>



<p>Finally, drag the BaseContainer from the Navigator and place it below the second button. Use the resizing handlers on the control to make it width and tall enough to fill all the remaining area on the window. The final layout should look more or less like this:</p>



<div class="wp-block-image is-style-default"><figure class="aligncenter"><img loading="lazy" decoding="async" width="1024" height="791" src="https://blog.xojo.com/wp-content/uploads/2021/12/AddControlUI-1024x791.png" alt="" class="wp-image-9795" srcset="https://blog.xojo.com/wp-content/uploads/2021/12/AddControlUI-1024x791.png 1024w, https://blog.xojo.com/wp-content/uploads/2021/12/AddControlUI-300x232.png 300w, https://blog.xojo.com/wp-content/uploads/2021/12/AddControlUI-768x593.png 768w, https://blog.xojo.com/wp-content/uploads/2021/12/AddControlUI.png 1346w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure></div>



<p>Use the Inspector Panel to set the following values:</p>



<ul class="wp-block-list"><li><strong>Locking:</strong> left, top, right and bottom clocks closed (locked)</li></ul>



<p>With the BaseContainer1 instance selected in the Layout Editor, add the ControlPressed Event to it and write the following line of code in the associated Code Editor:</p>



<pre class="wp-block-preformatted">ControlPressedName.Text = tControl.name</pre>



<h3 class="wp-block-heading">7. Running the App</h3>



<p>All set! Run the App, press the &#8220;Add Control&#8221; button to add as many buttons you want to the BaseContainer1 control, and press the &#8220;Remove Control&#8221; button to remove controls. Try to resize the window and you&#8217;ll see how the controls change their position as needed.</p>



<p><em>Paul learned to program in BASIC at age 13 and has programmed in more languages than he remembers, with Xojo being an obvious favorite. When not working on Xojo, you can find him talking about retrocomputing at <a href="https://goto10.substack.com" target="_blank" rel="noreferrer noopener">Goto 10</a> and </em>on Mastodon @lefebvre@hachyderm.io.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
