Well, the class I'm sing inherits its properties from the listbox, but it does have a property set sub. The code I'm using (go it from an online magazine) is as follows:
Look at the public property Font. It seems to be Read/Write. What am I missing?
Option Explicit On
Option Strict On
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Windows.Forms
Imports System.ComponentModel
Namespace WKS.ODListControl
'Enables code gen to convert prop builder strings to ODItem
<TypeConverter(GetType(ODItemConverter))> _
Public Class ODItem
Implements IDisposable
Implements IComparable
Private _Image As Image
Private _Font As Font
Private _ItemHeight As Integer
Private _UserObject As Object
Private _Text As String
Public Sub New()
_Text = "New item"
End Sub
Public Sub New(ByVal text As String)
_Text = text
End Sub
Public Sub New(ByVal text As String, ByVal itemImage As Image, ByVal itemHeight As Integer, ByVal Font As Font)
If Not IsNothing(itemImage) Then _Image = CType(itemImage.Clone, Image)
If Not IsNothing(Font) Then _Font = CType(Font.Clone, Font)
_ItemHeight = itemHeight
_Text = text
End Sub
Public Sub New(ByVal userObj As Object, ByVal text As String, ByVal itemImage As Image, ByVal itemHeight As Integer, ByVal Font As Font)
If Not IsNothing(itemImage) Then _Image = CType(itemImage.Clone, Image)
If Not IsNothing(Font) Then _Font = CType(Font.Clone, Font)
_ItemHeight = itemHeight
_UserObject = userObj
_Text = text
End Sub
Public Property ItemHeight() As Integer
Get
Return _ItemHeight
End Get
Set(ByVal Value As Integer)
_ItemHeight = Value
End Set
End Property
Public Property Image() As Image
Get
Return _Image
End Get
Set(ByVal Value As Image)
_Image = Value
End Set
End Property
Public Function ShouldSerializeImage() As Boolean
Return (Not IsNothing(_Image))
MsgBox("Called")
End Function
Public Property DisplayText() As String
Get
Return _Text
End Get
Set(ByVal Value As String)
_Text = Value
End Set
End Property
Public Property UserObject() As Object
Get
Return _UserObject
End Get
Set(ByVal Value As Object)
_UserObject = Value
End Set
End Property
Public Property Font() As Font
Get
Debug.WriteLine("Get font")
Return _Font
End Get
Set(ByVal Value As Font)
_Font = Value
End Set
End Property
Public Overloads Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Overloads Sub Dispose(ByVal disposing As Boolean)
If disposing Then
'Called by Dispose()
'Free managed objects
If Not IsNothing(_Image) Then _Image.Dispose()
If Not IsNothing(_Font) Then _Font.Dispose()
End If
'Free unmanaged objects.
End Sub
Protected Overrides Sub Finalize()
'Protected - don't allow to be called directly
Dispose(False)
End Sub
Public Overrides Function toString() As String
If Len(_Text) > 0 Then
Return _Text
ElseIf Not IsNothing(UserObject) Then
Return UserObject.ToString
Else
Return String.Empty
End If
End Function
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
If IsNothing(obj) OrElse IsNothing(obj.ToString) Then Return 1
Return String.Compare(ToString, obj.ToString)
End Function
End Class
End Namespace
Well, there it is... whatcha think?