Anchoring a label to the right so autoresize expands to the left.
Posted
#1
(In Topic #836)
Trainee
I'm creating an SMS application that has a large text area for entering an SMS message. Beneath that, I have 2 counters (as labels):
- keeps count of characters typed, and
- keeps count of SMS Count (being that an SMS is limited to 160 characters by SMSGlobal - my provider)
In design phase, my form looks as can be seen in attachment:
At run time, it appears as can be seen in attachment:
Is it possible to have a label be anchored on its right edge so that when it auto-resizes, it expands towards the left, similar to right justification in Word documents?
I know that I can change the Label's text property (which is how I've coded it for now), but I'd prefer to do it in code.
Cheers,
ak.
<COLOR color="#FF0000">UPDATE</COLOR>: I've identified that I can play around with .X and .Width to come up with a runtime solution:
Code
smsCount.X = SMSMessage.X + SMSMessage.Width - smsCount.WidthIf this is the only solution to my problem, then so be it.
Posted
Guru

Forum tip: - Use the 'gb' button for your code, the code will look better
<IMG src="https://www.cogier.com/gambas/gb_button.png">
</IMG>Code (gambas)
- smsCount.X = SMSMessage.X + SMSMessage.Width - smsCount.Width
And now to the Dark art of Gambas expanding forms! This is well worth getting your head around.
If the below is complicated, have a look at the attached program. Note that there is no code needed to get this to work.
1/. If you change the Form property Arrangement to Vertical. This will cause all the components to stack from the top to the bottom.
2/. Set the Form property Padding to 5. This will give you a nice border around your Form.
3/. I suggest the SMSMessage is a TextArea. Set the properties Expand and Wrap to True. The Expand will cause the TextArea to fill whatever space is available.
4/. To stop the 2 'Count' labels from piling on top of each other, you need to add a Hbox (Container tab of the toolbox) set it's Height to 28 and put the 2 Labels in it.
5/. Set the property Expand to True for both labels and on the right label change the Alignment to Right.
6/. Put the 2 Buttons in a HBox as well and add a Spring in between them to push them apart.
7/. You can add some Panels to act as voids if you want to move items further apart, see attached program.
<IMG src="https://www.cogier.com/gambas/ak2766.png">
</IMG>
Posted
Trainee
cogier said
Hi and welcome to the forum.
Forum tip: - Use the 'gb' button for your code, the code will look better
…
Thanks for the tip and detailed explanation on my problem, cogier, really appreciated.
1 guest and 0 members have just viewed this.





