stringwidth() pb / center label text
BlitzPlus Forums/BlitzPlus Programming/stringwidth() pb / center label text
| ||
| Hi ! Try the following code, i've an 'invalid blitz2d buffer Handle' error message. Could you explain why ? Perhaps have you another idea to center the text into the label ? Thanks !
Function Show_info_window(Message$)
f = LoadFont ("arial",14)
x = (GadgetWidth(Desktop())- 300) / 2
y = (GadgetHeight(Desktop())- 50) / 2
Win3 = CreateWindow("Hubitron",x,y,300,50,Desktop(),17)
SetFont f
w = StringWidth(Message$) ; <- ERROR : invalid blitz2d buffer Handle
Lbl = CreateLabel("",(300-w)/2,10,w,20,Win3,0)
SetGadgetFont lbl, f
SetGadgetText Lbl, Message$
End Function
Show_info_window("test")
|
| ||
| StringWidth() measures the width in pixels of the internal string image in B+ and B2D/3D. It isn't used for gadget text. I'm sure there were some commands added to deal with this, but I can't find documentation for them now. |
| ||
You get the error because you don't have a Buffer to draw to. Inserting the following lines after your 'SetFont' statement should fix it:canvas = CreateCanvas ( 0,0,10,10,Desktop() ) HideGadget canvas SetBuffer CanvasBuffer( canvas )This is probably a bug tho' (at least as far as I can tell), so you might want to post it in the bugreport forum aswell. |