Hi all,
been trying to sort this small problem fo 3 days now
I have an ownerdrawn listbox which displays an icon next to the item, and displays the text in a different colour. All working fine as a standard sized listbox but if I use a larger font then the text doesnt display properly and it still scrolls as if the standard size 8 font is used. I managed to get the text to display how I want it using ScaleTransform , it works well enougn until the listbox is required to scroll but then as I go down the selected items with the cursors (project is for a mousless project and scrollbars will be hidden) it just goes off the bottom of the visible area of the listbox.
Can anyone offer a way around this or an alternate method (an easy one as I'm not an expert!) All I need is a listbox with icons, colored text, and about size 20 font.
Thanks
Code for listbox:
been trying to sort this small problem fo 3 days now
I have an ownerdrawn listbox which displays an icon next to the item, and displays the text in a different colour. All working fine as a standard sized listbox but if I use a larger font then the text doesnt display properly and it still scrolls as if the standard size 8 font is used. I managed to get the text to display how I want it using ScaleTransform , it works well enougn until the listbox is required to scroll but then as I go down the selected items with the cursors (project is for a mousless project and scrollbars will be hidden) it just goes off the bottom of the visible area of the listbox.
Can anyone offer a way around this or an alternate method (an easy one as I'm not an expert!) All I need is a listbox with icons, colored text, and about size 20 font.
Thanks
Code for listbox:
Code:
' check if theres anything there, if not exit
If e.Index = -1 Then
Exit Sub
End If
'setup icons and brush etc ready
Dim myBrush As Brush = New SolidBrush(lstfiles.ForeColor)
Dim Icon As Drawing.Icon
'ok we'll try with 3, if this works then fine
Select Case e.Index Mod 3
Case 0
Icon = New Drawing.Icon("C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Graphics\icons\Win95\openfold.ico")
Case 1
Icon = New Drawing.Icon("C:\Documents and Settings\CALV\My Documents\My Completed Downloads\new juke\MMplayer\volume.ico")
Case 2
Icon = New Drawing.Icon("C:\Documents and Settings\CALV\My Documents\My Completed Downloads\new juke\MMplayer\mulmedia.ico")
End Select
e.Graphics.ScaleTransform(3, 3) '#######With this line removed it works fine but too small
e.DrawBackground()
Console.WriteLine("E.index is " & e.Index)
' e.Graphics.DrawIcon(Icon, New Rectangle(e.Bounds.X, e.Bounds.Y, 32, 32))
e.Graphics.DrawIcon(Icon, New Rectangle(e.Bounds.X, e.Bounds.Y + (e.Index * 25) + 0, 32, 42)) 'added the *25 or it doesnt line up
e.Graphics.DrawString(lstfiles.Items(e.Index), e.Font, myBrush, New RectangleF(e.Bounds.X + 12, e.Bounds.Y + 0, e.Bounds.Width, e.Bounds.Height))
e.DrawFocusRectangle()
End Sub