十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
VB.NET有很多值得學(xué)習(xí)的地方,這里我們主要介紹VB.NET Account對(duì)象,包括介紹是Load方法的Click事件等方面。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡(jiǎn)單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、網(wǎng)站空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、甘井子網(wǎng)站維護(hù)、網(wǎng)站推廣。
本文介紹三個(gè)文本框都用于保持當(dāng)前VB.NET Account對(duì)象的數(shù)據(jù)。它們分別叫txtAccountID、txtCustomerName和 txtBalance.顯示Load的按鈕叫btnLoad,用于載入帳號(hào)集合。另兩個(gè)按鈕在記錄間導(dǎo)航,分別叫btnBack 和 btnForward.
帳號(hào)對(duì)象集合可以保持在ArrayList(數(shù)組列表)中,因此下面一行代碼應(yīng)該在窗體代碼的最前面:
Dim colAccounts As ArrayList
下面是Load方法的Click事件代碼。它建立了一些VB.NET Account對(duì)象并把它們放入一個(gè)集合中,接著把該集合綁定到文本框。
- colAccounts = New ArrayList()
- colAccounts.Add(New Account(1, "ABC Company", 10))
- colAccounts.Add(New Account(2, "XYZ, Inc.", -10))
- colAccounts.Add(New Account(3, "MNP Limited", 0))
- txtAccountID.DataBindings.Add(New _
- Binding("Text", colAccounts, "AccountID"))
- txtCustomerName.DataBindings.Add(New _
- Binding("Text", colAccounts, "CustomerName"))
- txtBalance.DataBindings.Add(New _
- Binding("Text", colAccounts, "Balance"))
- txtBalance.DataBindings.Add(New _
- Binding("BackColor", colAccounts, "BackColor"))
注意最后兩行。txtBalance的Text屬性綁定到一個(gè)帳號(hào)的Balance屬性,并且該控件的BackColor屬性綁定到帳號(hào)對(duì)象的BackColor屬性。它演示了。NET框架組件綁定一個(gè)以上屬性到不同數(shù)據(jù)項(xiàng)。
現(xiàn)在點(diǎn)擊btnBack的Click事件,填入一下代碼:
- If Me.BindingContext(colAccounts).Position > 0 Then
- Me.BindingContext(colAccounts).Position -= 1
- End If
- 在btnForward的Click事件中寫入以下代碼:
- If Me.BindingContext(colAccounts).Position < colAccounts.Count - 1 Then
- Me.BindingContext(colAccounts).Position += 1
- End If