Results 1 to 4 of 4

Thread: [RESOLVED] Blurry Text From DrawItem Event in ListBox

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    [RESOLVED] Blurry Text From DrawItem Event in ListBox

    Hello,

    I've successfully changed the color of a Listbox using the DrawItem event. The text is blurry, however, like it was stretched to fill the rectangle. I attached a pic with the listbox on the left using DrawMode as OwnerFixed(therefore firing the DrawItem event) and the one on the right with DrawMode set to Normal. The right text is crisper and and more attractive while the left has that stretched out look to it. I don't believe the image shoes my issue well, because the effect isn't startling, just annoying.

    Name:  Capture.jpg
Views: 677
Size:  24.4 KB

    Here is my code for the DrawItem event for the left Listbox.

    Code:
        Private Sub lbRosterLeft_DrawItem(sender As Object, e As DrawItemEventArgs) Handles lbRosterLeft.DrawItem
    
            If e.Index = -1 Then Return
            Dim LB as Listbox = Directcast(sender, Listbox)     
            e.DrawBackground()
            Dim myBackColor As Color = Color.White
            Dim myForeColor As Color = Color.Black
            Dim Player As ClPlayer = m_League.GetProPlayerFromKey(m_StoredPlayerKeys(e.Index), -1)
            If Player.Injury.Count > 0 Then
                myForeColor = Color.Red
                For Each I As ClInjury In Player.Injury
                    If I.InjuredReserveDays > 0 Then myForeColor = Color.DarkRed
                Next
            ElseIf Player.OffFieldIssue.CurrentlySuspended = True Then
                myForeColor = Color.Gainsboro
            Else : myForeColor = Color.Black
            End If
            If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
                myBackColor = Color.CornflowerBlue
                myForeColor = Color.White
            End If
            Dim myBackgroundBrush = New SolidBrush(myBackColor)
            e.Graphics.FillRectangle(myBackgroundBrush, e.Bounds)
            Dim myForegroundBrush = New SolidBrush(myForeColor)
            e.Graphics.DrawString(LB.Items(e.Index).ToString(), e.Font, myForegroundBrush, e.Bounds.X, e.Bounds.Y)
            e.DrawFocusRectangle()
    
        End Sub
    Last edited by neef; Jun 10th, 2020 at 12:42 PM.
    Intermediate Level Programmer Extraordinaire

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Blurry Text From DrawItem Event in ListBox

    Try setting the Graphics.TextRenderingHint property to AntiAliasGridFit or ClearTypeGridfit before calling DrawString. You may also wish to experiment with the Graphics.TextContrast property (value 0 to 12, default 4) according to the black or white background; but I haven't tried it myself.

    BB

  3. #3

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    Re: Blurry Text From DrawItem Event in ListBox

    Thank you!

    e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit made it 90% better. I'll try the TextContrast too to perhaps make it even better.

    I appreciate your help!
    Eric
    Intermediate Level Programmer Extraordinaire

  4. #4
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,401

    Re: [RESOLVED] Blurry Text From DrawItem Event in ListBox

    My Github - 1d3nt

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