|
-
Jun 10th, 2020, 08:44 AM
#1
Thread Starter
Hyperactive Member
[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.

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 
-
Jun 10th, 2020, 09:47 AM
#2
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
-
Jun 10th, 2020, 12:40 PM
#3
Thread Starter
Hyperactive Member
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 
-
Jun 10th, 2020, 04:33 PM
#4
Re: [RESOLVED] Blurry Text From DrawItem Event in ListBox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|