国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Visual Basic 6.0 的 Controls 集合在 Visual Basic 2005 中

Visual Basic 6.0 的 Controls 集合在 Visual Basic 2005 中被替換為 ControlCollection 類。

概念差異

在 Visual Basic 6.0 中,Controls 集合是表示窗體或容器控件上的控件的元素的集合。

在 Visual Basic 2005 中,ControlCollection 類代替了 Controls 集合。窗體具有默認(rèn)的 ControlCollection 類,可以使用語(yǔ)法 Me.Controls 訪問(wèn)。

Add 方法

在 Visual Basic 6.0 中,Controls 集合的 Add 方法是后期綁定的;通過(guò)將 Control 類指定為參數(shù),在 Add 方法中創(chuàng)建控件。

在 Visual Basic 2005 中,在將控件添加到集合前,ControlCollection 類的 Add 方法要求使用 New 關(guān)鍵字創(chuàng)建控件。

Remove 方法

Visual Basic 6.0 Controls 集合的 Remove 方法只能用于使用 Add 方法添加的控件;Visual Basic 2005 ControlCollection 類沒(méi)有此限制。

計(jì)時(shí)器和菜單控件

在 Visual Basic 6.0 中,TimerMenu 控件是 Controls 集合的成員。在 Visual Basic 2005 中,這些控件替換為 TimerMainMenuContextMenu 組件;這些組件不是 ControlCollection 類的成員。

包含的控件

Visual Basic 6.0 Controls 集合包括作為容器控件的子控件的控件(如位于 Frame 控件上的控件);而 Visual Basic 2005 ControlCollection 類不是這樣。要循環(huán)訪問(wèn)窗體上的所有控件,則必須遞歸循環(huán)訪問(wèn)每個(gè)容器控件的 Controls 類。

控件集合的代碼更改

下面的示例演示 Visual Basic 6.0 和 Visual Basic 2005 在編碼方法上的不同之處。

添加和移除控件的代碼更改

下面的代碼說(shuō)明 Visual Basic 6.0 Controls 集合和 Visual Basic 2005 ControlCollection 類之間的差異。

 
復(fù)制代碼
' Visual Basic 6.0Private Sub Command1_Click()    ' Declare a new Control variable.    Dim c As Control    ' Create and add the new control.    Set c = Controls.Add("VB.TextBox", "Text1")    ' Make the new control visible.    c.Visible = True    ' Set the initial text.    c.Text = "Hello"    ' Retrieve the text from the new TextBox.    If Controls.Count > 1 Then        MsgBox (Controls("Text1").Text)    End If    ' Remove the new control.    Controls.Remove (Text1)    ' The following line causes a compilation error.    ' You cannot remove controls added at design time.    Controls.Remove (Command1)End Sub
Visual Basic 
復(fù)制代碼
' Visual Basic 2005Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click    ' Create a new TextBox control.    Dim TextBox1 As New System.Windows.Forms.TextBox    TextBox1.Name = "TextBox1"    ' Add the new control to the form's Controls collection.    Me.Controls.Add(TextBox1)    ' No need to set Visible property.    ' Set the initial text.    TextBox1.Text = "Hello"    ' Retrieve the text from the new TextBox.    If Me.Controls.Count > 1 Then        MsgBox(Me.Controls("TextBox1").Text)    End If    ' Remove the new control.    Me.Controls.Remove(TextBox1)    ' Remove the control added at design time.    Me.Controls.Remove(Button1)End Sub

循環(huán)訪問(wèn)控件集合的代碼更改

下面的代碼展示的函數(shù)循環(huán)訪問(wèn)窗體上的所有控件,然后清除所有 CheckBox 控件。本示例假定 CheckBox 控件位于 GroupBoxPanel 控件上,而不是窗體上。在 Visual Basic 2005 示例中,由于窗體的 Controls 集合僅包括直接位于窗體上的控件,所以該函數(shù)對(duì)具有子級(jí)的所有控件遞歸調(diào)用自身。

 
復(fù)制代碼
' Visual Basic 6.0Private Sub ClearChecks()    For Each Control in Me.Controls        If TypeOf Control Is CheckBox Then            Control.Value = vbUnchecked        End If    NextEnd Sub
Visual Basic 
復(fù)制代碼
' Visual Basic 2005Private Sub ClearChecks(ByVal Container As Control)    Dim ctl As Control    Dim chk As CheckBox    For Each ctl In Container.Controls        If TypeOf ctl Is CheckBox Then            chk = ctl            chk.Checked = False        End If        ' Recursively call this function for any container controls.        If ctl.HasChildren Then            ClearChecks(ctl)        End If    NextEnd Sub

升級(jí)說(shuō)明

由于 Visual Basic 6.0 和 Visual Basic 2005 Controls 集合之間的差異,對(duì) Add 方法的調(diào)用不進(jìn)行升級(jí)。必須添加代碼才能使用 Add 方法重新創(chuàng)建應(yīng)用程序的這一行為。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
遍歷aspx頁(yè)面中所有的指定控件
VB編程基礎(chǔ)教程16–對(duì)象之間的關(guān)系 | 異次元軟件世界
《Visual Basic 6.0項(xiàng)目教程(第3版)》項(xiàng)目5 設(shè)計(jì)多媒體程序
初中生也能學(xué)的編程不走彎路先用后學(xué)(Visual Basic環(huán)境)
Gambas,讓厚積的Visual Basic知識(shí)再度燦爛在Linux世界
.Net中的設(shè)計(jì)模式——Composite模式
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服