Hi guys,
I'm drawing a speech bubble on a gui. The text is put into a text label. I'm dynamically drawing the size of the textbox depending on the length of the string.
int chars;
int lines;
while (text.Length >= chars) {
lines++;
chars = chars+26;
}
gbubble.Height = 13*lines;// 13 is the height of the font
The problem is that this is unreliable, sometimes I end up with spare lines and sometime a word gets cut off.
Has anyone an idea of a more precise way of doing that?
Theres a function that calculates the width of a string in pixels based on the font but i cant remember exactly what it is.. check the manual.
Do something like this:
int width = GetTextWidth(text, gbubble.Font); // is gbubble the GUI or the label? If it's not the label replace it here with the label's name
gbubble.Height = GetTextHeight(text, gbubble.Font, width);
Thanks monkey- that sounds good. I'll try it right away
Note that in the case of an outlined font you have to calculate the width of the outline font instead.
Works smooth as silk! thanks guys