M
Manfred Denzer
Hello,
unfortunately, the property "AutoSize" doesn't work in Compact
Framework. So I have to set the size of my multiline TextBox manually.
I search a lot and found some solutions on the web. Often, I read the
hint to calculate the size of the text with Graphics.MeasureString:
http://www.eggheadcafe.com/software/aspnet/30758828/label-control-no-autosize.aspx
Now, I use this methode and calculate the lines:
SizeF textsize= g.MeasureString(control.Text, control.Font);
int lines = (int)textsize.Width / control.Width;
lines += (textsize.Width % control.Width) != 0 ? 1 : 0;
control.Height = lines * (int)textsize.Height;
But I'm sure that this solutions doesn't work in all cases! If there
is a long word in the TextBox and it doesn't fit completly in a line,
it will be displayed in the next line (like
JTextArea.setWrapStyleWord(true) in Java). So, in some cases it could
happen that the TextBox is to short.
What can I do the get the really number of lines of a TextBox?
Or is the a complete other solution for my problem? Maybe add the
TextBox in a Panel and use a LayoutManager like in Java? I'm new
in .NET CF and don't know if there are LayoutManagers.
Thank you very much!
unfortunately, the property "AutoSize" doesn't work in Compact
Framework. So I have to set the size of my multiline TextBox manually.
I search a lot and found some solutions on the web. Often, I read the
hint to calculate the size of the text with Graphics.MeasureString:
http://www.eggheadcafe.com/software/aspnet/30758828/label-control-no-autosize.aspx
Now, I use this methode and calculate the lines:
SizeF textsize= g.MeasureString(control.Text, control.Font);
int lines = (int)textsize.Width / control.Width;
lines += (textsize.Width % control.Width) != 0 ? 1 : 0;
control.Height = lines * (int)textsize.Height;
But I'm sure that this solutions doesn't work in all cases! If there
is a long word in the TextBox and it doesn't fit completly in a line,
it will be displayed in the next line (like
JTextArea.setWrapStyleWord(true) in Java). So, in some cases it could
happen that the TextBox is to short.
What can I do the get the really number of lines of a TextBox?
Or is the a complete other solution for my problem? Maybe add the
TextBox in a Panel and use a LayoutManager like in Java? I'm new
in .NET CF and don't know if there are LayoutManagers.
Thank you very much!