Autosize labels? Find text width?

I am building a multilingual application which includes dialogs for entering data such as name, phone, company etc.
Example:

Personal Data
Name: |_____________
Last Name: |_____________

Contact Data
Phone: |_____________

Please Note
You may edit this data any time later
by selecting ‘Data’, ‘Personal’ in the
menu.

There are a couple of things i cannot find in xojo and haven’t been able to figure out or find good examples of:

  • I need to find out how wide the labels are to position the column with text fields depending on how wide the first column with labels is.
  • In case of additional instructions (such as the ‘Please Note’ text), i need to be able to tell how high a label winds up being (since the width is limited by the dialog’s width).

In VB(A) i would use the AutoSize option, fill the text into the label and then ask it how wide it is. Or in the second case set AutoSize, set the width and then ask how high the label is.

Is there a simple way of solving this in xojo? And no, finding the language which requires the most space is not an option, as many of these dialogs will have to be dynamic!

Thanks in advance!!!

one way to find actual text size [off the top of my head… so you might have to tweak it]

function Label_Width(lbl as label)
dim s as string
dim p as picture
dim g as graphics
s=lbl.text
p=new picture(32,32,32)
g=p.graphics
g.textfont=lbl.textfont
g.textsize=lbl.textsize
return g.stringwidth(s)
end function

Take a look at Einhugur - FlowLayout

Thanks Dave, just tried it ound and it works great for simple labels (just one line of text). I found the solution for label height (for longer texts) as well (g.stringheight lets you pass the desired wrapwidth).

You saved the day!!!

And Paul, i will have to look into the flowlayout plugin - might be interesting for future projects …