Please contribute if you know alternate way to mix fonts on a single button. Hoping for a simpler way to do this, but this works for me. I haven't tested this for other types yet but this SetParent() approach should work with other gadget types, including ListIconGadget().
Code: Select all
; Sample code to show a single button sharing mixed fonts at the same time.
courier8.l = LoadFont(#PB_Default,"Courier",8)
arial8b.l = LoadFont(#PB_Default,"Arial",8,#PB_Font_Bold)
arial8.l=LoadFont(#PB_Default,"Arial",8)
HWND0 = OpenWindow(0,174,8,170,100,"Multi-Font Button",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If HWND0
; Setup font for main label.
SetGadgetFont(#PB_Default,FontID(courier8))
TextGadget(0,10,10,150,25,"Click the button.",#PB_Text_Center)
; Setup main font for button.
SetGadgetFont(#PB_Default,FontID(arial8b))
buttonMode = ButtonGadget(1,25,40,120,28,"Bright ",#PB_Text_Center)
; Setup alternate font for button.
SetGadgetFont(#PB_Default,FontID(arial8))
buttonAlt = TextGadget(2,60,6,50,15," > Dim",#PB_Text_Center)
; Here's the trick...
SetParent_(buttonAlt,buttonMode) ; attach alternate label gadget to main button
; Swap and show "current mode in bold" and "alternate mode as normal".
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If Mode.b ;
hBrush0 = CreateSolidBrush_(RGB(200,200,200))
SetClassLong_(HWND0, #GCL_HBRBACKGROUND, hBrush0)
InvalidateRect_(HWND0, #Null, #True)
SetGadgetText(1, "Bright ")
SetGadgetText(2, " > Dim")
Mode.b = 0
Else
Debug "off"
hBrush0 = CreateSolidBrush_(RGB(120,120,120))
SetClassLong_(HWND0, #GCL_HBRBACKGROUND, hBrush0)
InvalidateRect_(HWND0, #Null, #True)
SetGadgetText(1, "Dim ")
SetGadgetText(2, "> Bright")
Mode.b = -1
EndIf
EndSelect
EndSelect
Until EventID = #PB_Event_CloseWindow
EndIf
DeleteObject_(hBrush0) ; Cleanup
End