我想建立一个控件对象来更好地构建我的窗体。何时使用Inherits?
在下面,1个继承自某个类型的对象和1个被定义为特定类型的对象。
您能否告诉我何时使用ControlsCollection1和ControlsCollection2以及为什么不使用特定的控件。他们之间的区别?何时创建从现有对象继承的对象,以及何时将对象创建为某种类型的对象?
第二个问题,集合是否更好一个列表?
我还在学习,所以我希望这是有道理的。
Public Class ControlsCollection1
Private _controls As List(Of TextBox)
Private _textbox As TextBox
Public Sub New(ByVal textbox As TextBox)
Me._textbox = textbox
End Sub
Public Property Textbox() As TextBox
Get
Return _textbox
End Get
Set(ByVal value As TextBox)
_textbox = value
End Set
End Property
End Class
Public Class ControlsCollection2
Inherits List(Of TextBox)
End Class
调用类:
Dim col1 As New ControlsCollection1(New TextBox)
Dim col2 As New ControlsCollection2
col2.Add(New TextBox)