Classes

Hi, I’m very new to Xojo.

I’d like to centralize all my event handler code for a list box in a class.

But when I create a class the list box is greyed out.

i.e. if I wanted to centralize my code for every usage of the list box event handler BellBackground paint as in:

// Highlight ever other row

If row Mod 2 = 0 And AlternateHighlightCheckBox.Value Then
g.ForeColor = &cf3f6fA
g.FillRect(0, 0, g.Width, g.Height)
End If

thanks!
glen

[quote=48672:@Glen Newbury]Hi, I’m very new to Xojo.

I’d like to centralize all my event handler code for a list box in a class.
[/quote]
What you probably want to do is create a subclass of Listbox that has all your common code then use instances of that on your window layouts

To add to Norman’s answer, you also want to define a custom event in your subclass for CellBackgroundPaint (g As Graphics, Row As Integer, Column As Integer) As Boolean, then modify your custom code slightly:

if CellBackgroundPaint( g, Row, Column) then return true // The subclass handled it

// Highlight ever other row

If row Mod 2 = 0 And AlternateHighlightCheckBox.Value Then
g.ForeColor = &cf3f6fA
g.FillRect(0, 0, g.Width, g.Height)
End If

return true

When you add your ListBox subclass to your windows, there will still be a CellBackgroundPaint event, and if you return true from those, the subclass code won’t fire.

Thanks Norm, wow, 4 minutes, great forum! I didn’t realize I got the subclass under the list box.
and thanks Kem. Will try it tonight!

best regards,
Glen