Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/Listbox Row Colors


Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/Listbox Row Colors

This example is the version from Sun, 25th Jan 2020.

Project "Listbox Row Colors.xojo_binary_project"
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
End Project

See also:

The items on this page are in the following plugins: MBS MacControls Plugin.


The biggest plugin in space...