VB.NET Account对象简介
VB.NET有很多值得学习的地方,这里我们主要介绍VB.NET Account对象,包括介绍是Load方法的Click事件等方面。
本文介绍三个文本框都用于保持当前VB.NET Account对象的数据。它们分别叫txtAccountID、txtCustomerName和 txtBalance.显示Load的按钮叫btnLoad,用于载入帐号集合。另两个按钮在记录间导航,分别叫btnBack 和 btnForward.
帐号对象集合可以保持在ArrayList(数组列表)中,因此下面一行代码应该在窗体代码的最前面:
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框架组件绑定一个以上属性到不同数据项。
现在点击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
【编辑推荐】
- 简单描述VB.NET散列函数
- 详细分析VB.NET读写文本文件
- VB.NET GroupBox控件学习经验
- 概括VB.NET DomainUpDown控件
- VB.NET编码算法学习笔记
版权声明:
作者:后浪云
链接:https://www.idc.net/help/408232/
文章版权归作者所有,未经允许请勿转载。
THE END