首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

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

2012-03-09 
求助,关于重写或添加控件的属性,并且能够在设计器里体现出来我对控件的重写不是很熟悉,我现在想给control

求助,关于重写或添加控件的属性,并且能够在设计器里体现出来
我对控件的重写不是很熟悉,我现在想给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 PropertyEnd 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 PropertyEnd 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 PropertyEnd Class 

热点排行