 |
 |

07-15-2005, 02:40 AM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
custom listbox
|
Hi,
I'm trying to have a listbox with text and icons. My listbox isn't displaying anything because it's not going through the OnDrawItem procedure but I don't know how to make it do that. Thanks for any help.
This is what I have in my onload procedure ( have a listbox called lstText):
Dim lstText As CustomListBox = New CustomListBox
lstText.Items.Add(New CustomListBox("Image 1", New Icon("../Images/Icon16.ico")))
lstText.Items.Add(New CustomListBox("Image 2", New Icon("../Images/Icon16.ico")))
This is my CustomListBox class:
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Reflection
Imports System.Resources
Imports System.Windows.Forms
Public Class CustomListBox
Inherits ListBox
Private m_Icon As Icon
Public Sub New()
MyClass.New("", Nothing)
End Sub
Public Sub New(ByVal text As String, ByVal Icon As Icon)
Me.DrawMode = DrawMode.OwnerDrawFixed
m_Icon = Icon
End Sub
Private Function GetText() As String
Dim s As String
s = Text
return s
End Function
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim item As String
Dim br As Brush
item = GetText()
'Draw the icon
If Not m_Icon Is Nothing Then
e.Graphics.DrawIcon(m_Icon, e.Bounds.Left + 2, e.Bounds.Top + 2)
End If
'Draw the item
e.Graphics.DrawString(item, e.Font, New SolidBrush(e.ForeColor), e.Bounds.Left + 25, e.Bounds.Top + 2)
MyBase.OnDrawItem(e)
End Sub
Protected Overrides Sub OnMeasureItem(ByVal e As MeasureItemEventArgs)
e.ItemWidth = 300
e.ItemHeight = 100
End Sub
End Class
|
Last edited by stones75; 07-15-2005 at 06:01 AM.
|

07-15-2005, 07:27 AM
|
|
Centurion
|
|
Join Date: Jul 2003
Posts: 127
|
|
|
Have you ever thought about using the Listview control? You can add icons etc into it. You can also change the view, whether it be in columns, large icons, small icons or list. I think there are a few more, but ah well.
Chris
|
|

07-15-2005, 08:08 AM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
Quote:
|
Originally Posted by shiba126
Have you ever thought about using the Listview control? You can add icons etc into it. You can also change the view, whether it be in columns, large icons, small icons or list. I think there are a few more, but ah well.
Chris
|
Well I have other reasons for wanting to use a listbox
|
|

07-16-2005, 01:51 PM
|
|
Centurion
|
|
Join Date: Jul 2003
Posts: 127
|
|
|

07-18-2005, 07:32 AM
|
|
Newcomer
|
|
Join Date: Aug 2004
Posts: 13
|
|
Quote:
|
Originally Posted by shiba126
And these are....
|
Dosen't matter.
|
|

07-18-2005, 07:46 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
 attitude...
Is it going through the "OnMeasureItem". Have you set the OwnerDraw property of the listbox. The DrawItem and MeasureItem events will not fire unless this is set.
|
|

07-19-2005, 09:38 AM
|
|
Centurion
|
|
Join Date: Jul 2003
Posts: 127
|
|
Quote:
|
Originally Posted by stones75
Dosen't matter.
|
Then how can you expect help........
I think Iceplug was right - attitude
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|