我对控件的重写不是很熟悉,我现在想给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