On Oct 23, 2:49 pm, cgoet...@igpp.ucla.edu wrote:
> Hi All,
>
> How do I change the font and size of text on a button (or other
> widget)? For example...
>
> myButton = Widget_Button(myBase, value='Test')
>
> How can I change 'Test' to say 'Times' and increase it's size by 2.
> What are the size units?
>
> Thanks!
>
> Cindy
You can do all of the above with bitmap buttons. Write your text to a
bitmap using xyouts. Here is a code snippet from a routine of mine.
The text string you want is in 'text'. You should be able to control
the size with CharSize in XYOUTS, although I haven't tested that
particular option - there may be sizing conflicts with the multi-line
options.
Chad
wtlb = WIDGET_BASE()
wbtn = WIDGET_BUTTON(wtlb)
font = WIDGET_INFO(wbtn, /FontName)
WIDGET_CONTROL, wtlb, /Destroy
ss = GET_SCREEN_SIZE()
WINDOW, XSize=ss[0], YSize=ss[1], /Pixmap, /Free
DEVICE, Set_Font=font
nlines = N_ELEMENTS(text)
ysize = (!D.Y_CH_SIZE * nlines) < ss[1]
xx = FLTARR(nlines)
FOR i=0, nlines-1 DO BEGIN
XYOUTS, 0, 0, text[i], /Device, Font=0, CharSize=-1,
Width=xsize
xx[i] = xsize
XYOUTS, 0, 0, STRTRIM(text[i], 2), /Device, Font=0,
CharSize=-1, Width=xsize
ENDFOR
xsize = MAX(xx)*!D.X_VSIZE < ss[0]
xoffset = FLTARR(nlines)
FOR i=0, nlines-1 DO BEGIN
XYOUTS, 0, 0, STRTRIM(text[i], 2), /Device, Font=0,
CharSize=-1, Width=xo
xoffset[i] = (xsize - (xo*!D.X_VSIZE))/2
ENDFOR
WDELETE, !D.Window
border = 2
WINDOW, XSize=xsize + border*2, YSize=ysize + (nlines*border ) +
border, /PixMap, /Free
ERASE, 255
FOR i=0, nlines-1 DO $
XYOUTS, border + xoffset[i], !D.Y_SIZE - ( (i+1) * (border+!
D.Y_CH_SIZE) ), $
STRTRIM(text[i], 2), /Device, Font=0, Color=0
b = TVRD()
WDELETE, !D.Window
r = b
g = b
|