<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=How_to_Visually_Float_a_Control</id>
	<title>How to Visually Float a Control - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=How_to_Visually_Float_a_Control"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=How_to_Visually_Float_a_Control&amp;action=history"/>
	<updated>2026-11-21T18:54:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=How_to_Visually_Float_a_Control&amp;diff=4074&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;If you need to position an object so that it remains its natural size, but floats centered in an area, you can use dSizers and spacers to achieve this.  For example, let&#039;s say...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=How_to_Visually_Float_a_Control&amp;diff=4074&amp;oldid=prev"/>
		<updated>2020-05-11T22:18:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;If you need to position an object so that it remains its natural size, but floats centered in an area, you can use dSizers and spacers to achieve this.  For example, let&amp;#039;s say...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;If you need to position an object so that it remains its natural size, but floats centered in an area, you can use dSizers and spacers to achieve this.&lt;br /&gt;
&lt;br /&gt;
For example, let&amp;#039;s say that you want a label centered horizontally on a form. You&amp;#039;d first create a horizontal sizer, and then add the label surrounded by spacers. The trick is to give the spacers proportions of 1 and the label a proportion of 0. Here&amp;#039;s what the code would look like, assuming that self is the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
lbl = dabo.ui.dLabel(self, Caption=&amp;quot;I&amp;#039;m in the middle!&amp;quot;)&lt;br /&gt;
sz = dabo.ui.dSizer(&amp;quot;h&amp;quot;)&lt;br /&gt;
sz.appendSpacer(1, proportion=1)&lt;br /&gt;
sz.append(lbl, proportion=0)&lt;br /&gt;
sz.appendSpacer(1, proportion=1)&lt;br /&gt;
self.Sizer.append(sz, &amp;quot;expand&amp;quot;)&lt;br /&gt;
self.layout()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we instructed the form&amp;#039;s sizer (&amp;lt;code&amp;gt;self.Sizer&amp;lt;/code&amp;gt;) to expand &amp;lt;code&amp;gt;sz&amp;lt;/code&amp;gt; to take up all available width.&lt;br /&gt;
&lt;br /&gt;
Another option would have been:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
self.Sizer.append(sz, halign=&amp;quot;center&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would have left &amp;lt;code&amp;gt;sz&amp;lt;/code&amp;gt; using its minimal size and just positioned the whole &amp;lt;code&amp;gt;sz&amp;lt;/code&amp;gt; sizer in the center of &amp;lt;code&amp;gt;self.Sizer&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Neat trick&amp;#039;&amp;#039;&amp;#039; - When running an application in which you are using the dabo base menu (the&lt;br /&gt;
default) there is the option under &amp;#039;&amp;#039;&amp;#039;View&amp;#039;&amp;#039;&amp;#039; to &amp;#039;&amp;#039;&amp;#039;Show Sizer Lines&amp;#039;&amp;#039;&amp;#039;. This makes a big difference in trying to see what is happening with the instructions you are providing.&lt;br /&gt;
&lt;br /&gt;
Another option, assuming that you have a single vertical sizer for the form, is to add the label, being sure to set the &amp;lt;code&amp;gt;halign&amp;lt;/code&amp;gt; parameter when adding to the sizer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
lbl = dabo.ui.dLabel(self, Caption=&amp;quot;I&amp;#039;m in the middle!&amp;quot;)&lt;br /&gt;
self.Sizer.append(lbl, halign=&amp;quot;center&amp;quot;)&lt;br /&gt;
self.layout()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is like the previous example but without using the second sizer.&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>