Platforms to show: All Mac Windows Linux Cross-Platform
/Main/Listbox CellBackgroundPaint Example
Required plugins for this example: MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Listbox CellBackgroundPaint Example
This example is the version from Fri, 5th Apr 2012.
Project "Listbox CellBackgroundPaint Example.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
EventHandler Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
if me.ListIndex<>row then
g.DrawPicture pic, 20, -row*me.RowHeight
Return true
end if
End EventHandler
End Control
Control Listbox2 Inherits Listbox
ControlInstance Listbox2 Inherits Listbox
EventHandler Function CellBackgroundPaint(g As Graphics, row As Integer, column As Integer) As Boolean
if row = me.ListIndex then // don't overdraw normal highlight
Return false
end if
if Row<me.ListCount then
dim v as Variant = me.CellTag(row, 0)
if v isa Picture then
dim p as Picture = v
g.DrawPicture p, 1, 1, 14, 14, 0, 0, p.Width, p.Height
Return true
elseif v.Type = v.TypeColor then
dim c as color = v
g.ForeColor = c
g.FillRect 0, 0, g.Width, g.Height
Return true
end if
end if
End EventHandler
EventHandler Sub Open()
me.ColumnAlignmentOffset(0) = 20
End EventHandler
End Control
EventHandler Sub Open()
pic = LogoMBS(200)
for i as integer = 1 to 20
listbox1.AddRow str(i)
listbox2.AddRow str(i)
next
// draw pic in some cells
listbox2.CellTag(5,0) = pic
listbox2.CellTag(8,0) = pic
listbox2.CellTag(9,0) = pic
listbox2.CellTag(12,0) = pic
listbox2.CellTag(19,0) = pic
// draw color in some other cells
listbox2.CellTag(2,0) = RandomColor
listbox2.CellTag(3,0) = RandomColor
listbox2.CellTag(10,0) = RandomColor
listbox2.CellTag(11,0) = RandomColor
listbox2.CellTag(18,0) = RandomColor
End EventHandler
Function RandomColor() As Color
// gives a light color
Return rgb(127+rnd*128, 127+rnd*128, 127+rnd*128)
End Function
Property pic As Picture
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project
See also:
The items on this page are in the following plugins: MBS Main Plugin.