which webcontrol is good for dynamic string length?

Hi Guys,

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

I hope for your help.
Thanks in advance

I wish somebody will notice my concern and provide me suggestions. up!

link text

Because you want to do something does not mean someone has done it before and is ready to share.

The big issue here is to figure the size of the text, in order to change that of the control.

You could use graphics.TextHeight and wrapwidth to check the size of the text, and from that, figure the size of the control.


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 font size has been set with a WebStyle.

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?

GraffitiWebLabel supports dynamic height.

That link post is really messed up

Hi Michel,

Thanks for the idea but looks not not supported on xojo web.

g.FontName = “System”
g.FontSize = 12

Anyway, GrafittiWeblabel works!

Thanks for all your reply guys. My agony is gone!

Oh, but fonts and font size are supported by WebStyles, as I duly mentioned in my post. Perhaps I should abstain trying to help anymore :confused:

Your help is always appreciated. I learn a lot with your posts. Thank you.

Hi Michel,

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. :slight_smile:

Thank you so much.

yeah. but my requirment is that I need show all the text content and eliminate the scroll bar.

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.

GraffitiWebLabel has a Resized event that is raised when its size changes due to the content. Resize your container from that event.

1 Like

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

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

I got error on this part

This is not an array but you are using it as one

int1 = Floor(pic.Graphics.TextHeight(label1.Text, CType(Me.Width, Double))) + 5