Results 1 to 3 of 3

Thread: [RESOLVED] ListBox Bounds are incorrect

  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  

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: ListBox Bounds are incorrect

    try increasing the ItemHeight property of the listbox.
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2010
    Posts
    26

    Re: ListBox Bounds are incorrect

    Wow, so simple and yet I never would of thought of changing that. I figured that property would have been updated once the new font was entered.

    Thank you.

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