使用对象类作为属性,该对象类包含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
错误提示:类型“WindowsControlLibrary1.UserControl1+TabTagUserDraw”的对象无法转换为类型“WindowsControlLibrary1.UserControl1+TabTagUserDraw”
这种情况是在修改了子属性以后发生的,比如在IDE环境下修改Font为“隶体”,查找了一天也没有找出原因...
只有减少了点属性设置就解决了
本案例把以下语句:
<Serializable(), StructLayout(LayoutKind.Sequential), TypeConverter(GetType(ExpandableObjectConverter))> _
Class TabTagUserDraw
改变为下面的语句,问题就解决了:
<TypeConverter(GetType(ExpandableObjectConverter))> _
Class TabTagUserDraw