vb.net控件阵列 vb列表控件

vb.net 怎样创建控件数组?Dim Str(20) As String '20数据元素
Dim Text(20) As TextBox
【vb.net控件阵列 vb列表控件】Dim n As Integer = 0
For Each i In Text
i = New TextBox '实例化
i.Location = New Point(50, n * 20)
Me.Controls.Add(i) '添加窗体
Dim Index As Integer = i.TabIndex '没index属性
Str(n) = Index
i.Text = Str(n) 'str数组值赋值给文本框
n += 1
Next
[VB.NET]读取TXT的资料存到阵列之中用自定义类型数组处理:
Private Structure PhoneBook
Dim ID As Integer
Dim name As String
Dim sex As Boolean
Dim phone As String
Dim email As String
Dim group As String'这里也可以设置为整数型,用序号来代表各个组
End Structure
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim PBook() As PhoneBook, tmpstr() As String, iCount As Integer = 0
Dim str As IO.StreamReader = New IO.StreamReader("C:\1.txt", System.Text.Encoding.Default)
Do Until str.EndOfStream
tmpstr = Split(str.ReadLine(), ",")
If tmpstr.Length = 6 Then
ReDim Preserve PBook(iCount)
PBook(iCount).ID = CInt(tmpstr(0))
PBook(iCount).name = tmpstr(1)
If tmpstr(2) = "男" Then PBook(iCount).sex = True Else PBook(iCount).sex = False
PBook(iCount).phone = tmpstr(3)
PBook(iCount).email = tmpstr(4)
PBook(iCount).group = tmpstr(5)
iCount += 1
End If
Loop
str.Close()
End Sub
vb.net如何使用控件数组,希望可以用label为例vb.net和vb6.0不同vb.net控件阵列,无法直接使用控件数组 。不过可以通过其vb.net控件阵列他方式变通一下 。
比如现在有10个labelvb.net控件阵列 , 要将这10个labelvb.net控件阵列的text属性统一设置为“这是第X个标签”(X为1-10) 。
1.建立10个label,名称分别为label1、label2、label3 。。label10
2.代码vb.net控件阵列:
For i = 1 To 10
Me.FindControl("label"i).Text = "这是第"i“个标签”
Next i
关键点是Me.FindControl()的方法,在代码中Me.FindControl("label1").text与label1.text是一样的 。
VB 实现阵列表述Option Explicit
Option Base 1
Private Function Search(ByVal target As Long, ByRef arr() As Long, ByRef index1 As Long, ByRef index2 As Long) As Boolean
For index1 = LBound(arr, 1) To UBound(arr, 1)
For index2 = LBound(arr, 2) To UBound(arr, 2)
If arr(index1, index2) = target Then
Exit For
End If
Next
If index2 = UBound(arr, 2) Then Exit For
Next
Search = (index1 = UBound(arr, 1))
End Function
Private Sub Form_Load()
On Error Resume Next
Dim arr(3, 6) As Long
Dim i As Long, j As Long, k As Long
For i = LBound(arr) To UBound(arr)
For j = LBound(arr, 2) To UBound(arr, 2)
arr(i, j) = (j - 1) * 3 + i
Next
Next
k = Val(InputBox("请输入需查找的值", "输入", 0))
'找到了
If Search(k, arr, i, j) Then
MsgBox "第"i"行 第"j"列"
Else
MsgBox "没找到"
End If
End Sub
关于vb.net控件阵列和vb列表控件的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读