I am working with a web app to read SMS from a device.
My struggle now is finding a web control that is adaptive to the length of the sms message.
Adaptive means, I can able to manipulate the height and width of the web control that exactly fits with the whole message (without the need to show the scrollbar).
Here is an example in a WebTextArea. This in Shown, and in TexChanged, will set the vertical size to that of the text:
Sub TextChanged() Handles TextChanged
dim p as new picture(1,1)
dim g as graphics = p.Graphics
g.FontName = "System"
g.FontSize = 12
me.height = g.TextHeight(me.Text, me.width)
End Sub
The biggest issue you will encounter is that by default controls in Xojo web have a fixed size as defined in the layout editor. Have you thought about using a read-only text area and just let it scroll?
Your help in this forum keeps me positive to continue XOJO as my primary dev tools.
Actually, I used snippets mac app to save tips and codes and the majority of the code there came from your help.
If this is for Web 1.0, GraffitiWebLabel has AutoHeight functionality. It will automatically size itself to the content and width that it’s given. You already have this in your toolbox and didn’t know it.
Thanks Anthony. I tried it Graffitweb and weblabel works as it was described. However, my weblabel is inside the webcontainer which must also resize based on the size of weblabel. This is what I can’t figure out how.
We are calculating the height of an element like containercontrols and such using a little hack:
var int as Integer
var pic as new Picture(WebLabel1.Width, WebLabel1.Height)
int = floor(pic.Graphics.TextHeight(val, cType(WebLabel1.Width, Double))) + 5
Quick Tip to save memory and make the code reusable
Private Function CalculateHeight(obj As WebUIControl, value As String) As Integer
Static pic As Picture
If pic Is Nil Then
pic = New Picture(1, 1)
End If
Return Floor(Pic.Graphics.TextHeight(value, obj.Width) + 5)
End Function