You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Threads/Listbox InvalidateCell on Thread
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run()
dim n as integer = 0
do
me.Sleep(1000)
colors(n) = rgb(rnd*256, rnd*256, rnd*256)
Listbox1.InvalidateCellThreadSafeMBS n,0
n = n +1
if n = 10 then n = 0
loop
End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
EventHandler Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
if row<=UBound(colors) then
g.ForeColor = colors(row)
g.FillRect 0, 0, g.Width, g.Height
Return true
end if
End EventHandler
EventHandler Sub Open()
for i as integer = 0 to 9
me.AddRow ""
colors.Append rgb(rnd*256, rnd*256, rnd*256)
next
End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
EventHandler Sub Open()
Thread1.run
End EventHandler
Property colors() As color
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