You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/Listbox Row Colors
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub AppearanceChanged()
QueryRowColors
// refresh windows
For i As Integer = WindowCount-1 DownTo 0
window(i).Invalidate
Next
End EventHandler
EventHandler Sub Open()
QueryRowColors
End EventHandler
Shared Sub QueryRowColors()
// our defaults
RowColorEven = &cFFFFFF
RowcolorOdd = &cEEFFEE
#if TargetMacOS then
dim colors() as NSColorMBS = NSColorMBS.alternatingContentBackgroundColors
if colors = nil then
break
return // should not happen
end if
if colors.Ubound = 1 then
// 2 colors
RowColorEven = colors(0).colorValue
RowColorOdd = colors(1).colorValue
end if
#endif
End Sub
Property Shared RowColorEven As color
Property Shared RowColorOdd As color
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
if me.ListIndex = row then
// let Xojo draw selection
else
if row mod 2 = 0 then
g.ForeColor = app.RowColorEven
else
g.ForeColor = app.RowColorOdd
end if
g.FillRect 0, 0, g.Width, g.Height
end if
End EventHandler
End Control
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar