Private Sub ListBox1_DrawItem(sender As System.Object, e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
[I]'this routine sets everything from the 3rd character to bold in the selected item only
'you'll have to adapt the item and substring selection to your own needs
[/I]
Dim normal As String[I] 'substring to be drawn normally[/I]
Dim bold As String [I]'substring to be bolded[/I]
Dim NewX = e.Bounds[I] 'needed to ensure that the bold section doesn't overwrite the normal section[/I]
Dim f = New Font(e.Font, FontStyle.Bold)[I] 'sets font to bold[/I]
Try
If e.Index = ListBox1.SelectedIndex Then
normal = ListBox1.Items(e.Index).ToString
bold = normal.Substring(2)
normal = normal.Substring(0, 2)
NewX.X = e.Bounds.X + ((normal.Length + 3) * e.Font.Unit) [I]'this shifts the drawing point past the first two characters
'it will need tinkering with for each different font[/I]
[I] 'there's almost certainly a better way to do it but I haven't discovered it yet![/I]
e.Graphics.DrawString(normal, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault)
[I]'bold's not necessarily easily distinguished so you can change text colour as well [/I]
e.Graphics.DrawString(bold, f, Brushes.Red, NewX, StringFormat.GenericDefault)
Else[I] 'this provides the default drawing for all other items[/I]
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString, e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault)
End If
Catch
End Try
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox1.Refresh() [I]' this must be done to ensure repaint, add it to a suitable event or at the end of your selection process[/I]
End Sub