Anchoring a label to the right so autoresize expands to the left.

Post

Posted
Rating:
#1 (In Topic #836)
Trainee
I'm very new to Gambas but not to programming.

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):

  1. keeps count of characters typed, and
  2. 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:
Image

(Click to enlarge)


At run time, it appears as can be seen in attachment:
Image

(Click to enlarge)


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.Width

If this is the only solution to my problem, then so be it.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi and welcome to the forum.

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)

  1. 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>

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#3
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.
Online now: No Back to the top
1 guest and 0 members have just viewed this.