desktopLabel.with

Hello

I want to display a desktop label whose width depends on the length of the text.

Do you know if it’s possible?

Thank you for your help

If it affects other controls you might want to check out the Einhugur FlowLayout plugin, which is for this purpose.

If you’d rather build it yourself, you can try setting all the text properties the same and getting the TextWidth from a Graphics object.

1 Like

Merci Tim , c’est exactement ce que je recherchais

NOTE. If you are building for MS-Windows, TextWidth might not always give you the correct result.

This is because the the UI controls in Xojo are GDI based but the Xojo Graphics APIs use Direct2D.

1 Like

Thank you for this information

Now my code is :

 Var lab_nbCaracteres As Integer = 0

lab_nbCaracteres = 0

Var p As New Picture ( Label( 0 ).Width , Label( 0 ).Height )
Var tx_w As Double
Var tx_w_Max As Integer

For Each de As DictionaryEntry In Me.dico_ChampsRes
tx = “”
tx = de.Key.StringValue
tx_w = p.Graphics.TextWidth ( tx )
If   tx_w > tx_w_Max Then
tx_w_Max = tx_w
End If
Next

Label( index ).Width = lab_W