Results 1 to 3 of 3

Thread: [RESOLVED] ListBox Bounds are incorrect

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    26

    Resolved [RESOLVED] ListBox Bounds are incorrect

    Hello,

    So I've finally moved into the VB.NET world and have a quick question. I am drawing a ListBox control with DrawItem event. The problem I am having is that the e.bounds region does not match my text. I changed the font of my ListBox to a larger one with ListBox.Font = New Font(...). Below is my code, when the text is printed it overlaps, slightly, with other rows. Also, I did change the DrawMode to OwnerDrawFixed. When I click the list box, I get a focus rectangle and my highlighted background, but they are displayed as if a default (smaller) font is is used. I've attached a picture to show you.

    Code:
    Private Sub lstScript_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles lstScript.DrawItem
            Dim MyBrush As Brush = Brushes.LightGray
    
            'e.DrawBackground()
    
            If (e.State = (DrawItemState.Focus Or DrawItemState.Selected)) Then
                e.Graphics.FillRectangle(SelectColor, e.Bounds)
            Else
                e.Graphics.FillRectangle(Brushes.White, e.Bounds)
            End If
    
            e.Graphics.FillRectangle(MyBrush, 0, e.Bounds.Top, 20, ScriptFont.Height)
            e.Graphics.DrawString(lstScript.Items(e.Index).ToString(), e.Font, Brushes.Black, e.Bounds.X + 20, e.Bounds.Y)
    
            e.DrawFocusRectangle()
    
        End Sub
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width