modularbeing
Regular
- Joined
- Jan 8, 2004
- Messages
- 63
I am trying to get a little fancy with a list box and use the owner drawn feature to change the look. I have written some code to change the look of the selected item but i cannot figure out how I can reverse it when someone clicks another item.
Here is the code I wrote to do this:
Here is the code I wrote to do this:
Code:
Private Sub listBox1_DrawItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground()
Dim l As ListBox = CType(sender, ListBox)
Dim stringSize As SizeF = e.Graphics.MeasureString(l.SelectedItem, New Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold))
If ((DrawItemState.Selected) > 0) Then
Dim selRect As New Rectangle(e.Bounds.X, e.Bounds.Y, l.Width - 1, stringSize.Height / 2)
Dim br As New SolidBrush(Color.FromArgb(206, 223, 255))
e.Graphics.FillRectangle(br, selRect)
e.Graphics.DrawRectangle(New Pen(Color.FromArgb(30, 108, 253), 1), selRect)
e.Graphics.DrawString(l.Items(e.Index), e.Font, Brushes.Black, New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
br.Dispose()
End If
End Sub