All pastes #43983 Raw Edit

Someone

public text v1 · immutable
#43983 ·published 2006-03-01 03:54 UTC
rendered paste body
    Private Sub ReaderDataListBox_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ReaderDataListBox.DrawItem
        ' Set the DrawMode property to draw fixed sized items.
        sender.DrawMode = DrawMode.OwnerDrawFixed
        ' Draw the background of the ListBox control for each item.
        e.DrawBackground()

        ' Create a new Brush and initialize to a Black colored brush by default.
        Dim myBrush As Brush

        'If e.State And DrawItemState.Selected = DrawItemState.Selected Then
        'myBrush = Brushes.White
        'Else
        myBrush = Brushes.Black
        'End If

        Dim seperator As Char() = {Microsoft.VisualBasic.ChrW(Keys.Tab)}
        If e.Index >= 0 Then
            Dim strings As String() = CType(sender.items(e.Index), String).Split(seperator, 3)
            ' we should have 3

            ' find width of column1
            Const col1_width As Integer = 100
            Const col3_width As Integer = 130

            Dim col1_start As Integer = e.Bounds.X
            Dim col2_start As Integer = e.Bounds.X + col1_width
            Dim col2_width As Integer = e.Bounds.Width - col1_width - col3_width
            Dim col3_start As Integer = e.Bounds.X + col1_width + col2_width

            ' Draw the current item text based on the current Font and the custom brush settings.
            e.Graphics.DrawString(strings(0), e.Font, myBrush, New RectangleF(col1_start, e.Bounds.Y, col1_width, e.Bounds.Height))
            e.Graphics.DrawString(strings(1), e.Font, myBrush, New RectangleF(col2_start, e.Bounds.Y, col2_width, e.Bounds.Height))
            e.Graphics.DrawString(strings(2), e.Font, myBrush, New RectangleF(col3_start, e.Bounds.Y, col3_width, e.Bounds.Height))
        End If

        ' If the ListBox has focus, draw a focus rectangle around the selected item.
        e.DrawFocusRectangle()
    End Sub