VB.Net中文教程(1) 类别与封装性(4)

页面导航:首页 > 软件编程 > vb.net > VB.Net中文教程(1) 类别与封装性(4)

VB.Net中文教程(1) 类别与封装性(4)

来源: 作者: 时间:2016-02-05 12:32 【

This call is required by the Win Form Designer. InitializeComponent() TODO: Add any initializatio

 

 

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()

       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 a As New Tree()

       a.input(2.1)

       MessageBox.Show("OK")

   End Sub

End Class

 

   将input()摆在Tree类别中﹐为Tree之程序成员﹐它能存取资料成员height之值。把input()程序宣告为Public表示类别外之程序可藉来呼叫它﹐其呼叫格式为──

               

  简单规则是﹕

      Public 表示授权给外界之程序藉由此格式呼叫程序成员。

 

如果此程序改写为﹕

 

 

 

ex09.bas

Some Error Here!

Imports System.ComponentModel

Imports System.Drawing

Imports System.WinForms

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

Class Tree

   Private varity As String

   Private age As Integer

   Private height As Single

   Private Sub input(ByVal hei As Single)

       height = hei

   End Sub

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()

       components.Dispose()

   End Sub

#Region " Windows Form Designer generated code "

   .......

Tags:

文章评论


<