last time.
BlitzPlus Forums/BlitzPlus Programming/last time.
| ||
Guess this is the last time i will bother asking this as I have wasted a days programming already! I think there is an incconsistency between StringWidth() and GadgetWidth() do they even take parameters in pixels? I want to create a label: txt$ = "123" CreateLabel( txt$, 0,0, StringWidth(txt$), FontHeight(), hnd ) the label width does not match the width of the string, ie: StringWidth(txt$) returns 32, the label at 32 pixels wide is greater than required for a string of "123". I will be creating various labels of differing widths and need to centre them relative to a panel gadget so i really, really need to set the label dimensions to match that of the string. |
| ||
How do you reckon that? In this code: SetBuffer (DesktopBuffer()) win=CreateWindow("blah",0,0,300,300,0,33) txt$ = "123" mylab=CreateLabel ( txt$, 0,0, StringWidth(txt$), FontHeight(), win ) DebugLog StringWidth(txt$) DebugLog GadgetWidth (mylab) StopStringWidth and GadgetWidth both return 24. Please explain the problem in greater detail. |
| ||
Nigel - I understand your problem because I have it as well. :) The issue is this: StringWidth doesn't return the width of an API type string, but the width of a string using the current canvas font. You might try loading a the same Windows font to an invisible canvas and checking the width of that. Hope this helps. |
| ||
Yeah, I had the same problem. You must load a font to be able to use Stringwidth() |
| ||
Hey thanks for that, looked under the appearance setings and found that Tahoma was the font and its size was 8, doesn't quite match but it is close and I am sure I can get it to work from here thanks again. |
| ||
The problem is you don't know what your users have on their computer, so I guess you can call the API to find that out, at which point I stop caring much about how wide my gadgets are. |