
正文
vb.net阵列 vba 数组阵列赋值
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.NET 生成按钮
Public Sub GenerateDynamiceButton()
'建立 坐标位置的变数, 方便一会儿安排 自动生产的button 的位置
Dim y As Integer = 15
Dim x As Integer = 0
' 用for loop 来建立 这些button 做 18只button
For ButtonIndex As Integer = 0 To 17
' 建造新的 button
Dim MyButton As New Button
'设定这新的button 的阔度
MyButton.Width = 80
'设定这新的button 的高度
MyButton.Height = 20
'我们暂定每行有4个BUTTON, 当每行有多个4个BUTTON 时重设行距, 令到下一行的和这一行的距离有10 个PIXEL
' 和重设x 坐标` = 0, 令到位置由头开始
If ButtonIndex Mod 4 = 0 Then
'设定 TOP 的 坐标位置令他可以和上一排的有10个PIXEL 的距离
y += MyButton.Height + 10
x = 0
End If
'设定文字 和 位置
' Set the text and set its top and left based on its dimensions and count
MyButton.Text = "My Button" ButtonIndex
'设定 TOP 的 坐标位置
MyButton.Top = y
'下面的CODE 可以令到这个BUTTON 和另一个BUTTON 有5个PIXEL 的距离
MyButton.Left = 26 + (x * (MyButton.Width + 5))
x += 1
'设定 BUTTON CLICK EVENT
AddHandler MyButton.Click, AddressOf MyButton_Click
'把button 加到 form 中
Me.Controls.Add(MyButton)
Next
End Sub
'处理 button click event
Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim btn As Button = sender
'pop up 一个自己button 的字的message
MsgBox(btn.Text)
相关问答
Q1: [VB.NET]读取TXT的资料存到阵列之中
用自定义类型数组处理vb.net阵列:
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 '这里也可以设置为整数型vb.net阵列,用序号来代表各个组
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
Q2: VB.NET 字串用换行分割
假设你要分割vb.net阵列的字符串是string1的话
分割代码就是vb.net阵列:
dim s as string=strings.split(string1,vbcrlf)
这样s就是一个阵列vb.net阵列了。s(0)是第一段内容vb.net阵列,s(1)是第二段内容,以此类推。~~
googles8 的写法也对的。不过vb.net阵列我的代码省去了声明的一行。只用一行就好了。
vb.net阵列的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vba 数组阵列赋值、vb.net阵列的信息别忘了在本站进行查找喔。







