新聞中心
VB.NET有很多值得學(xué)習(xí)的地方,這里我們主要介紹VB.NET Account對象,包括介紹是Load方法的Click事件等方面。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:空間域名、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、甘井子網(wǎng)站維護、網(wǎng)站推廣。
本文介紹三個文本框都用于保持當(dāng)前VB.NET Account對象的數(shù)據(jù)。它們分別叫txtAccountID、txtCustomerName和 txtBalance.顯示Load的按鈕叫btnLoad,用于載入帳號集合。另兩個按鈕在記錄間導(dǎo)航,分別叫btnBack 和 btnForward.
帳號對象集合可以保持在ArrayList(數(shù)組列表)中,因此下面一行代碼應(yīng)該在窗體代碼的最前面:
Dim colAccounts As ArrayList
下面是Load方法的Click事件代碼。它建立了一些VB.NET Account對象并把它們放入一個集合中,接著把該集合綁定到文本框。
- 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屬性綁定到一個帳號的Balance屬性,并且該控件的BackColor屬性綁定到帳號對象的BackColor屬性。它演示了。NET框架組件綁定一個以上屬性到不同數(shù)據(jù)項。
現(xià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
新聞標(biāo)題:VB.NETAccount對象簡介
瀏覽路徑:http://www.5511xx.com/article/dpgogjj.html


咨詢
建站咨詢
