专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

,关于重写或添加控件的属性,并且能够在设计器里体现出来

发布时间:2011-06-23 16:01:56 文章来源:www.iduyao.cn 采编人员:星星草
求助,关于重写或添加控件的属性,并且能够在设计器里体现出来
我对控件的重写不是很熟悉,我现在想给control类增加一个属性,或者覆盖原有的属性,这个属性是我自己定义的一个类。而当我在设计器中添加一个控件时,我又想在设计器里看到这个属性,应该如何做?

------解决方案--------------------
自定义类,继承自Control。拖自定义的控件出来用。你无法修改现有控件改继承你的控件。
------解决方案--------------------
先写一个继承类
VB.NET code
Public Class ExTextBox
    Inherits TextBox

    Private nShowText As Boolean

    Public Property ShowText() As Boolean
        Get
            Return nShowText
        End Get
        Set(ByVal value As Boolean)
            nShowText = value
            If nShowText Then
                MyBase.Text = "您好"
            End If
        End Set
    End Property
End Class

------解决方案--------------------
Public Class CustomControl
Inherits System.Windows.Forms.Control
Private _MyProperty As ClassA
<System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _
Public Property MyProperty() As ClassA
Get
Return _MyProperty
End Get
Set(ByVal value As ClassA)
_MyProperty = value
End Set
End Property

End Class


<System.ComponentModel.TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))> _
Public Class ClassA
Private newPropertyValue As String
Public Property NewProperty() As String
Get
Return newPropertyValue
End Get
Set(ByVal value As String)
newPropertyValue = value
End Set
End Property

End Class
------解决方案--------------------
VB.NET code

Public Class CustomControl
    Inherits System.Windows.Forms.Control
    Private _MyProperty As ClassA
    <System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _
    Public Property MyProperty() As ClassA
        Get
            Return _MyProperty
        End Get
        Set(ByVal value As ClassA)
            _MyProperty = value
        End Set
    End Property

End Class


<System.ComponentModel.TypeConverterAttribute(GetType(System.ComponentModel.ExpandableObjectConverter))> _
Public Class ClassA
    Private newPropertyValue As String
    Public Property NewProperty() As String
        Get
            Return newPropertyValue
        End Get
        Set(ByVal value As String)
            newPropertyValue = value
        End Set
    End Property

End Class
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: