This content has been marked as final. Show 8 replies
Well the margin values on all text boxes are something like 2 pixels on each side and that is a constant. So that shouldn't matter. Unless you have a large text field and you aren't resizing it.
So be sure to set the autoSize property on you text field to true.
And don't use a center aligned textfield. Use a left aligned text field. Then when it changes center it on the place it needs to go and position the other two relative to that.
Thanks for the reply.
Unfortunately, the margins on each side are different for each letter and for each font.
Why was getTextExtent deprecated?
If getTextExtent still exists, it may help me position my +/- button:-(
I just made 5 or 6 different text boxes and changed the size of each and selected a few random fonts from my list. If all the textfields lined up at 100 then all the words started within a fraction of a pixel of 102.
So I don't think you understand what I'm saying. Make sure you have your textfield autoSize set to true. In that case there will be no margins because the textfield will size itself to the size needed for the text. Then you will know how wide the text is.
Yes getTextExtent is still there it was a mistake in the documentation that said it was depreciated. However there are a few times where it doesn't actually work well and in those cases what you do is make an invisible textfield with autosize set to true and measure the sizes there. Exactly what I am telling you here.
Rothrock, I really appreciate your help. I understand what you mean. However, some fonts work like what you say. But some don't.
Can you try this font with this text "font size"? The font is free.
Here is the code that I use.
dtFontSize.text = "font size";
dtFontSize.autoSize = "left";
btFontDecrease._width = btFontIncrease._width;
btFontIncrease._x = dtFontSize._x - btFontIncrease._width;
btFontDecrease._x = dtFontSize._x + dtFontSize._width;
Here are 2 screenshots.
1.gif is the zoom in version in design mode. As you can see, the "spacing/margin" of the 1st and the last letter are different already.
2.gif is the version in run time. The calculated positions are even worse.
What do you think?
I haven't come up with a solution. My guess is that it is a combination of things.
First with free things you often get what you pay for. I'm not sure, but some fonts have some kinda crazy metrics and glyph placements.I tried experimenting with some of the more exuberant cursive fonts on my maching and the "f" didn't move over the way it seems to for your example. So I would suggest tyring it with just some regular font like Arial or Verdana and seeing if it works there.
I might also try turing on the border and background for the text fields and see if you can figure out anything regarding the placement for those.
I would probably also break apart the de/increase buttons from text fields so they are just artwork.
I think you are right that the font was not well designed. Thank you for your suggestion.