当前位置:编程学习 > VB >>

VB.Net中文教程(4) 母子对象关系(4)

 

 

public Overrides Sub Dispose()

       MyBase.Dispose()

       components.Dispose()

   End Sub

  

#Region " Windows Form Designer generated code "

    ......

#End Region

   Protected Sub Form1_Click(ByVal sender As Object,

                           ByVal e As System.EventArgs)

       Dim r As New MyRoom()

       r.Show()

   End Sub

End Class

 

此程序输出:

              Room Size: 100

              Desk Size:  18

 

3. 特类别继承与母子对象

 

   您已很熟悉父子类别关系了﹐这继承关系的另一面是母子对象关系。例如﹐

 

ex06.bas

Imports System.ComponentModel

Imports System.Drawing

Imports System.WinForms

----------------------------------------------------

Class Room

   Private mother As MyRoom

  

   Public Sub New(ByVal mo As MyRoom)

       mother = mo

   End Sub

   Public Function GetID() As String

       GetID = mother.yourID()

   End Function

End Class

 

Class MyRoom

   Inherits Room

  

   Public Sub New()

       MyBase.New(Me)

   End Sub

   Public Function yourID() As String

       yourID = "VIP888"

   End Function

End Class

----------------------------------------------------

Public Class Form1

   Inherits System.WinForms.Form

  

   Public Sub New()

       MyBase.New()

       Form1 = Me

       This call is required by the Win Form Designer.

       InitializeComponent()

       TODO: Add any initialization after the InitializeComponent() call

   End Sub

   Form overrides dispose to clean up the component list.

   Public Overrides Sub Dispose()

       MyBase.Dispose()

      

补充:软件开发 , Vb ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,