Custom fixed size listbox items in IronPython in 30 seconds
Just a reminder so I can remember how to draw fixed height custom listbox items. Syntax highlighting would be nice … ho hum.
class MyForm(Form):
def __init__(self):
self.listbox = ListBox( Location=... )
self.listbox.DrawMode = DrawMode.OwnerDrawFixed
self.listbox.ItemHeight = 80
self.listbox.DrawItem += self.drawListboxItem
# Add your items as necessary, remembering they don't need to be strings
self.Controls.Add( self.listbox )
""" Called when an item needs drawing
evt is a DrawItemEventArgs """
def drawListboxItem(self, sender, evt):
# Draw the default background
evt.DrawBackground()
# Get the item that is being drawn
item = self.listbox.Items[evt.Index]
# Use the Graphics object to draw your item using evt.Bounds to
# determine where to draw (pay attention to the evt.Bounds.X and
# evt.Bounds.Y
evt.Graphics.Draw...
# Draw the selection rectangle
evt.DrawFocusRectangle()
1 year ago