首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ProvideProperty作为对象

使用ProvideProperty作为对象
EN

Stack Overflow用户
提问于 2011-11-28 03:46:15
回答 1查看 500关注 0票数 0

我想在设计器中使用一个ProvideProperty为Object的类,但是当属性是object时,我似乎不能使用它。字符串可以很好地工作。

我可以在代码中设置和获取,但不能在设计器中设置和获取。

大thx

我的代码:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-28 04:51:29

正常情况下,您可以将至少一个类似

属性的字符串

如果字符串足够好,则可以应用TypeConverter属性:

代码语言:javascript
复制
<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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8288470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档