使用自定义类作为属性提示无法转换,如何处理?
使用对象类作为属性,该对象类包含Font、Color、StringAlignment等类型的子属性。在使用时出现下面的错误提示,请问应如何处理?
类型“WindowsControlLibrary1.UserControl1+TabTagUserDraw”的对象无法转换为类型“WindowsControlLibrary1.UserControl1+TabTagUserDraw”
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Public Class UserControl1
Inherits System.Windows.Forms.TabControl
Private TabTag As New TabTagUserDraw
<Browsable(True), Category("外观"), Description("设置标签前景色、背景色及字体")> _
Public Property TabTagAppearance() As TabTagUserDraw
Get
Return TabTag
End Get
Set(ByVal value As TabTagUserDraw)
TabTag.Aligment = value.Aligment
TabTag.Font = value.Font
TabTag.BackColor = value.BackColor
TabTag.ForeColor = value.ForeColor
End Set
'NotifyPropertyChanged
End Property
<Serializable(), StructLayout(LayoutKind.Sequential), TypeConverter(GetType(ExpandableObjectConverter))> _
Class TabTagUserDraw
Private tabTagColor As Color = Color.White
Private tabFont As Font = New Font("宋体", 10)
Private FontColor As Color = Color.Black
Private StringF As StringAlignment = StringAlignment.Center
<DefaultValue(GetType(Color), "Black")> _
Public Property ForeColor() As Color
Get
Return FontColor
End Get
Set(ByVal value As Color)
FontColor = value
End Set
End Property
<DefaultValue(GetType(Color), "White")> _
Public Property BackColor() As Color
Get
Return tabTagColor
End Get
Set(ByVal value As Color)
tabTagColor = value
End Set
End Property
<DefaultValue(GetType(Font), "宋体,10")> _
Public Property Font() As Font
Get
Return tabFont
End Get
Set(ByVal value As Font)
tabFont = value
End Set
End Property
Public Property Aligment() As StringAlignment
Get
Return StringF
End Get
Set(ByVal value As StringAlignment)
StringF = value
End Set
End Property
End Class
End Class
[解决办法]
很正常,呵呵,把我们当“橡皮鸭”把
呵呵,我会经常把我对面做的那位喊过来当“橡皮鸭”滴
小黄鸭调试法