Fixing a TextBox Size

Gianmaria
10-12-2007, 05:02 AM
Hi,
i'm using textboxes to mark some places on the map customizing the text.

I use:


tbox = Shapes.AddTextbox(Location, 1, 1);


and later i modify the size to adapt to the text:


tBox.Width = getWidthByString(textToDisplay);


the getWidthByString is a my custom function that calculate the size analyzing the string and adding 11pts if a char is lower and 12pts if a char is upper:


private int getWidthByString(string name)
{
int w = 0;
foreach (char c in name)
{
if (Char.IsLower(c)) { w += 11; }
if (Char.IsUpper(c)) { w += 12; }
}
return w;
}


but this seem to dont have a regular behaviuor.. i always have txtboxes larger than i need....


Any Idea?

Gianmaria

Wilfried
10-16-2007, 08:03 AM
Hi,

The text is proportional font. A lot of characters are the same size, but for the smaller and larger ones you have to put a case statement in your width calculation routine.

I think the most easy is to make a textbox with all characters in it. Then copy the map with textbox to clipboard, then paste it in your favourite picture editor and zoom it in and count the pixels for each character.

 
Web mp2kmag.com
mapforums.com