Vb.net 将ProvideProperty用作对象
我想在disigner中使用提供property作为对象的类,但当属性是对象时,我似乎无法使用它。一根绳子很好用 我可以在代码中设置和获取,但不能在设计器中设置和获取 大thx 我的代码:Vb.net 将ProvideProperty用作对象,vb.net,object,properties,designer,Vb.net,Object,Properties,Designer,我想在disigner中使用提供property作为对象的类,但当属性是对象时,我似乎无法使用它。一根绳子很好用 我可以在代码中设置和获取,但不能在设计器中设置和获取 大thx 我的代码: Imports System.Windows.Forms Imports System.ComponentModel <ProvideProperty("Champ", GetType(Control))> _ <ProvideProperty("Valeur", GetType(Cont
Imports System.Windows.Forms
Imports System.ComponentModel
<ProvideProperty("Champ", GetType(Control))> _
<ProvideProperty("Valeur", GetType(Control))> _
<ProvideProperty("Comparaison", GetType(Control))> _
Public Class ProprietesEtendues
Implements IExtenderProvider
Public Enum CompareType
Egal
Different
PlusGrand
PlusGrandEgal
PlusPetit
PlusPetitEgal
End Enum
Private _champ As New Dictionary(Of IntPtr, String)
Private _val As New Dictionary(Of IntPtr, Object)
Private _comp As New Dictionary(Of IntPtr, CompareType)
'Propriété Comparaison
Public Function GetChamp(ByVal c As Control) As String
Dim strRetour As String = ""
_champ.TryGetValue(c.Handle, strRetour)
Return strRetour
End Function
<DefaultValue(""), Category("Data"), Description("Ajoute une propriété de type String")> _
Public Sub SetChamp(ByVal c As Control, ByVal value As String)
_champ(c.Handle) = value
End Sub
'Propriété Valeur
Public Function GetValeur(ByVal c As Control) As Object
Dim objRetour As Object = ""
_val.TryGetValue(c.Handle, objRetour)
Return objRetour
End Function
<DefaultValue(""), Category("Data"), Description("Ajoute une propriété de type Object")> _
Public Sub SetValeur(ByVal c As Control, ByVal value As Object)
_val(c.Handle) = value
End Sub
'Propriété Comparaison
Public Function GetComparaison(ByVal c As Control) As CompareType
Dim ctRetour As CompareType = CompareType.Egal
_comp.TryGetValue(c.Handle, ctRetour)
Return ctRetour
End Function
<DefaultValue(CompareType.Egal), Category("Data"), Description("Ajoute une propriété de type CompareType")> _
Public Sub SetComparaison(ByVal c As Control, ByVal value As CompareType)
_comp(c.Handle) = value
End Sub
Public Function CanExtend(ByVal target As [Object]) As Boolean Implements IExtenderProvider.CanExtend
Return True
End Function
End Class
导入System.Windows.Forms
导入System.ComponentModel
_
_
_
公共类专有职业
实现IExtenderProvider
公共枚举区类型
伊格尔
不同的
普鲁斯格兰德
普卢斯格兰德加尔
长发
多价
结束枚举
Private _champ作为新词典(IntPtr的字符串)
Private _val作为新字典(用于IntPtr,对象)
Private _compas New Dictionary(IntPtr的CompareType)
"本来面目"(Propriétécomparison)
公共函数GetChamp(ByVal c作为控件)作为字符串
Dim stretour As String=“”
_champ.TryGetValue(c.Handle,Strertour)
返回strertour
端函数
_
公共子SetChamp(ByVal c作为控件,ByVal值作为字符串)
_champ(c.Handle)=值
端接头
“固有价值”
作为对象的公共函数GetValeur(ByVal c作为控件)
Dim objRetour As Object=“”
_val.TryGetValue(c.Handle,objRetour)
返回对象
端函数
_
公共子SetValeur(ByVal c作为控件,ByVal值作为对象)
_val(c.Handle)=值
端接头
"本来面目"(Propriétécomparison)
公共函数GetComparison(ByVal c作为控件)作为CompareType
作为CompareType的Dim ctRetour=CompareType.Egal
_组件TryGetValue(c.手柄、ctRetour)
返回ctRetour
端函数
_
公共子集比较(ByVal c作为控件,ByVal值作为CompareType)
_组件(c.手柄)=值
端接头
公共函数CanExtend(ByVal目标为[Object])作为布尔值实现IExtenderProvider.CanExtend
返回真值
端函数
末级
通常,您至少可以放置一个类似于Tag属性的字符串 如果字符串足够好,则可以应用[TypeConverter]属性:
<TypeConverter(GetType(StringConverter))> _
Public Function GetValeur(ByVal c As Control) As Object
Dim objRetour As Object = ""
_val.TryGetValue(c.Handle, objRetour)
Return objRetour
End Function
<DefaultValue(""), Category("Data"), Description("Ajoute une propriété de type Object")> _
<TypeConverter(GetType(StringConverter))> _
Public Sub SetValeur(ByVal c As Control, ByVal value As Object)
_val(c.Handle) = value
End Sub
_
作为对象的公共函数GetValeur(ByVal c作为控件)
Dim objRetour As Object=“”
_val.TryGetValue(c.Handle,objRetour)
返回对象
端函数
_
_
公共子SetValeur(ByVal c作为控件,ByVal值作为对象)
_val(c.Handle)=值
端接头
PropertyGrid不知道如何使Object类型的属性可编辑。它可以是任何东西。通常,您至少可以放置一个字符串,如Tag属性。