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

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

 

 

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 "

   .......

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