ぽちグラマー的 .Netに戻る
VB.Netでの継承で覚えなくてはならないのが【Inherits】というものがあります。
Public Class TextBox1 −>継承クラス、子クラス
Inherits TextBox −>基底クラス、スーパークラス
また、継承でよく使われる
Overloads オーバーロード既存メンバの機能拡張
言い方を変えれば「メンバの追加」
Public Class TextBox1
Inherits TextBox
Public Overloads Function ToString(ByVal text As String) As String
Return Me.Text += text
End Function
End Class
Overrides オーバーライド既存メンバの機能変更
Public Class TextBox1
Inherits TextBox
Public Overrides Property Text() As String
Get
Return Me.Text.Trim()
End Get
Set(ByVal value As String)
MyBase.Text = value.Trim()
End Set
End Property
End Class
サンプルソース
Public Class TextBox1
Inherits TextBox
Public Overloads Function ToString(ByVal text As String) As String
Return Me.Text += text
End Function
Public Overrides Property Text() As String
Get
Return Me.Text.Trim()
End Get
Set(ByVal value As String)
MyBase.Text = value.Trim()
End Set
End Property
End Class
|