• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

集团在自定义的控件属性

用户头像
it1352
帮助1

问题说明

在我们的IDE,比如,Visual Studio中,如果我们显示System.Windows.Forms.Button控件的属性,我们可以看到一些属性,揭露anoter的属性集。例如: FlatAppearance,字体,位置,保证金的,等等

In our IDE, for example, Visual Studio, if we display the properties of a System.Windows.Forms.Button control, we see some properties that expose anoter set of properties. For example: FlatAppearance, Font, Location, Margin, etcetera.

我希望做一个自定义的控制类似的东西。

I would like to do something similar in a custom control.

我知道code的背后是错误,但这里是什么I'm试图做一个例子:

I know the code behind is wrong, but here is an example of what I´m trying to do:

Public Class StateOfMyCustomControl

    Public Enum EnumVisibility
        Visible
        NonVisible
    End Enum

    Public Enum EnumEventManagement
        Automatic
        Manual
    End Enum

    Private mAssociatedControl As MyCustomControl
    Private mVisibility As EnumVisibility
    Private mEventManagement As EnumEventManagement

    Public Sub New(ByVal AssociatedControl As MyCustomControl)
        mAssociatedControl = AssociatedControl
    End Sub

    Public Property Visibility() As EnumVisibility
        Get
            Return mVisibility
        End Get
        Set(ByVal value As EnumVisibility)

            mVisibility = value

            mAssociatedControl.Visible = False
            If mVisibility = EnumVisibility.Visible Then
                mAssociatedControl.Visible = True
            End If

        End Set
    End Property

    Public Property EventManagement() As EnumEventManagement
        Get
            Return mEventManagement
        End Get
        Set(ByVal value As EnumEventManagement)
            mEventManagement = value
        End Set
    End Property

End Class

Public Class MyCustomControl

    ' ...

    Private mState As StateOfMyCustomControl

    Public Sub New()
        mState = New StateOfMyCustomControl(Me)
    End Sub

    Public Property State() As StateOfMyCustomControl
        Get
            Return mState
        End Get
        Set(ByVal value As StateOfMyCustomControl)
            mState = value
        End Set
    End Property

    ' ...

End Class

在我的IDE,在我的自定义控件的属性窗口,我想看看我的财产的国家的,以显示它的可能性来设置属性的能见度的和 EventManagement 的。

In my IDE, in the properties window of my custom control, I would like to see my property State, with the possibility of display it to set the properties Visibility and EventManagement.

非常感谢

正确答案

#1

您需要告诉它使用 ExpandableObjectConverter (或自定义转换器)的 StateOfMyCustomControl 。在C#中,这就是:

You need to tell it to use ExpandableObjectConverter (or a custom converter) for StateOfMyCustomControl. In C#, this is:

[TypeConverter(typeof(ExpandableObjectConverter))]
public class StateOfMyCustomControl {...}

不过你申请的属性在VB中,做到这一点;-p

However you apply attributes in VB, do that ;-p

可能:

<TypeConverter(GetType(ExpandableObjectConverter))> _
Public Class StateOfMyCustomControl
...

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangkajbj
系列文章
更多 icon
同类精品
更多 icon
继续加载