B Bill Norris Active Member Licensed User Longtime User May 20, 2012 #1 In stringutils, we have the MeasureMultilineTextHeight feature to help determine the proper height of a label with multiple lines of text. I would like a similar feature to get the width of a text string, so as to set the width of a label dynamically based on the length of the text assigned to it. Any ideas on getting some kind of "text width" ??
In stringutils, we have the MeasureMultilineTextHeight feature to help determine the proper height of a label with multiple lines of text. I would like a similar feature to get the width of a text string, so as to set the width of a label dynamically based on the length of the text assigned to it. Any ideas on getting some kind of "text width" ??
Erel B4X founder Staff member Licensed User Longtime User May 20, 2012 #2 You can calculate it with Canvas.MeasureStringWidth. Upvote 0
B Bill Norris Active Member Licensed User Longtime User May 21, 2012 #3 RE: To experiment with this, I put in the following code in a button click event: Code: Copy Dim C As Canvas Dim X As Int X=C.MeasureStringWidth("textwidth",default_font,30) Msgbox(x,"") I received a Null Pointer Exception error when I ran it. BTW, value of default_font is assigned in activity_create, and functions as desired throughout the app. Upvote 0
RE: To experiment with this, I put in the following code in a button click event: Code: Copy Dim C As Canvas Dim X As Int X=C.MeasureStringWidth("textwidth",default_font,30) Msgbox(x,"") I received a Null Pointer Exception error when I ran it. BTW, value of default_font is assigned in activity_create, and functions as desired throughout the app.
klaus Expert Licensed User Longtime User May 21, 2012 #4 You must initialize the Canvas: Code: Copy Dim C As Canvas C.Initialize(Activity) Dim X As Int X = C.MeasureStringWidth("textwidth", default_font, 30) Msgbox(x,"") Best regards. Upvote 0
You must initialize the Canvas: Code: Copy Dim C As Canvas C.Initialize(Activity) Dim X As Int X = C.MeasureStringWidth("textwidth", default_font, 30) Msgbox(x,"") Best regards.