Hello. First of all, I am using C# Compact Framework 2.X. Now, I have a label control, and its text is set dynamically, so I don't know what size to set it. If only I could measure how much space was needed for the text, I could manually move all of the controls around it and manually set the label's size.
Now, I know about the Graphics.measureString() method. This only measures a string horizontally, not vertically (i.e. word wraps make the text go to the next lines; I need to know how many vertical lines of text there are).
Also, I tried measuring the entire string width as if it were on one line, and dividing that by the width of the label to see how many lines of text there are. This doesn't work when you have odd strings such as strings with really long words or newlines.
So, is there a way to measure how many lines are needed when you word wrap to a specific width?
Thanks!
Loading
Jan MontanoPosted Feb 11, 2009, 7:19 PM
Honestly I haven't used the .net compact framework yet and haven't yet done any mobile applications.
I advise you to create another thread with a different title. if there's a .net compact framework section. post it there. In my opinion, you'll get fewer response now because this thread already has replies (In my case, i normally just browse those without replies =D). So an unanswered thread will definitly attract more readers than an answered one.
m qPosted Feb 11, 2009, 11:46 AM
I tried looking into the source code of the label as well. Basically a label is nothing more than a wrapper for the class Control, which has its own Text property.
public virtual void set_Text(string value)
{
if (this.Text != value)
{
PAL_ERROR ar = WL.SetText(this.m_hwn, value, (value == null) ? 0 : value.Length);
}
}
So, this WL reference is Microsoft.AGL.Forms.WL.
[DllImport("AGL", EntryPoint="@39")]
public static extern PAL_ERROR SetText(IntPtr hwnThis, string rgwch, int cch);
The wrapping code is done in a native library. Bummer! This is a really bad problem. What happens when I receive dynamic text, such as from a web call? Or, what about trying to adjust for several different languages? How does one ensure the proper size of a label in Compact Framework 2?
Thanks for any help!
Jan MontanoPosted Feb 8, 2009, 10:48 PM
By default in my IDE, the label's AutoSize property is set to true. Perhaps your label's AutoSize property is set to false. Just change it to TRUE then.
m qPosted Feb 5, 2009, 9:31 PM
Jan MontanoPosted Feb 5, 2009, 7:26 PM
Why do you need to change the label's size when it's size is automatically changing depending on it's text value.