very basic question about subclassing

I have no experience with subclassing stuff in Xojo or any other language so I am groping here.

I want to subclass the CheckBox control and add a TextColor property for the label but I can not figure out how to do this. I would be most grateful if you just point me at the proper documentation on how to do this.


AFAIK there’s no way to do this with a standard Xojo checkbox regardless of subclassing or not. You could do several things:

  1. check to see if a 3rd party control, like Graffiti Suite has a checkbox that does this
  2. make your own using a container, a checkbox with no caption, and label of your own. Then declare events on the container to mimic the checkbox events.

Of the two, option 2 is the cheap version and the one you have the most control over.

thanks again Bob

BTW, don’t know if you are a Chiefs fan or not but Mahomes is a local boy from the next town over and was a local hero in high school and college. Congrats to the Chiefs.

it is unusual that a CheckBox did not have a Label Color and we need to use a workaround …

If you are macOS only and have access to the MBS plugins here is a rough example i’ve just knocked up that shows how it could be done.

NOTE. The property TextColor below should be enabled in the control’s Inspector Behaviour.

[code]Class cCheckBox
Inherits Checkbox
Event Open()
Sub Open()
'update the initial appearance of the caption

'raise the open event again so that it can be hooked into
RaiseEvent Open
End Sub

Private Sub UpdateCaption()
Dim attributedStringObj As NSAttributedStringMBS
Dim mutableAttributedStringObj As NSMutableAttributedStringMBS

If Self.NSButtonMBS <> Nil Then
attributedStringObj = NSAttributedStringMBS.attributedStringWithString(Self.Caption)
mutableAttributedStringObj = attributedStringObj.mutableCopy
mutableAttributedStringObj.addAttribute(NSAttributedStringMBS.NSForegroundColorAttributeName, New NSColorMBS(Self.mCaptionColour_), New NSRangeMBS(0, Len(Self.Caption)))

  Self.NSButtonMBS.attributedTitle = mutableAttributedStringObj

End If
End Sub

Property Caption As String
Return CheckBox(Self).Caption
End Get

CheckBox(Self).Caption = value

End Set
End Property

Private mCaptionColour_ As Color

Property TextColor As Color
Return Self.mCaptionColour_
End Get

Self.mCaptionColour_ = value

End Set
End Property
End Class[/code]

Pftt! Of course I’m a Chiefs fan. I watched every single one of the games when they were 2-14 (twice). I’ve been to training camp 8 years in a row. And stood out in sub-freezing temps to celebrate their Super Bowl victory. :slight_smile:

you sure your not a browns fan ?
sounds equally dedicated