vb.net定义控件数组,vb如何创建控件数组
vb.net2013中创建控件数组
我是VB.Net 2010,你看看能行不。
玄武网站建设公司成都创新互联公司,玄武网站设计制作,有大型网站制作公司丰富经验。已为玄武上1000家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的玄武做网站的公司定做!
Public Class Form1
Private MyTextBoxArray As New ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 0 To 8 '利用循环语句动态加入控件数组。
Dim FirstTextBox As New TextBox
'定义文本框对象
Me.Controls.Add(FirstTextBox)
'将一个文本框控件加入到Form上
MyTextBoxArray.Add(FirstTextBox)
'将文本框控件加入到例表集合中
MyTextBoxArray.Item(i).top = i * MyTextBoxArray.Item(i).height + 20 '修改新加入控件在Form上的位置
MyTextBoxArray.Item(i).left = 100
FirstTextBox.TabIndex = i
'修改新加入控件的TabIndex值
MyTextBoxArray.Item(i).text = "TextBox" i.ToString '修改默认文本。
Next
End Sub
End Class
vb.net中定义控件数组,控件数组中加入多个按钮。怎么能在控件数组事件响应对应按钮的事件,代码部分:
Dim bt As New ArrayList
bt.Add(Me.Button5)
bt.Add(Me.Button6)
bt.Add(Me.Button7)
上面这段代码本人表示不懂,故没有使用。下面的代码在VS2015中运行通过:
Private Sub btClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click, Button6.Click, Button7.Click
Select Case CType(sender, Button).Name
Case "Button5"
MessageBox.Show("你点击了 Button5 按钮")
Case "Button6"
MessageBox.Show("你点击了 Button6 按钮")
Case "Button7"
MessageBox.Show("你点击了 Button7 按钮")
End Select
End Sub
在VB.net里定义的控件数组怎么定义事件
Imports System.Text
Imports System.Windows
Imports System.Windows.Forms
Public Class Netin '类 名
'Inherits Forms.Form
Public Shared Netin As New Form
Public components As ComponentModel.IContainer
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
DebuggerStepThrough()
Public Sub InitializeComponent()
Me.components = New ComponentModel.Container()
Dim resources As ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(bjt))
Me.TextBox1 = New TextBox(Me.components)
Me.Button1 = New Button(Me.components)
'For … Next
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.m = New ContextMenuStrip(Me.components)
Me.m1.Text = "菜单项1"
'设置并添加相关控件,(窗体)Netin 初始化。
End Sub
Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
'加载后显示窗体Netin。
End Sub
Public Sub ObjClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click,Button2.Click,Button3.Click,TextBox1.Click
MessageBox.Show("你按了鼠标")
End Sub
Public WithEvents TextBox1 As TextBox
Public WithEvents Button1 As Button
Public WithEvents Button2 As Button
Public WithEvents Button3 As Button
Friend WithEvents m As ContextMenuStrip
Friend WithEvents m1 As ToolStripMenuItem
End Class
Class MainWindow
Netin.Show()
Netin.Button2.Text = "Main"
……
vb.net 数组的定义方法
1、vb.net的
数组定义与变量定义差不多。可以用
dim
来定义
比如:
dim
a(100)
as
integer。
也可以不定义下标
在程序中
用
redim
来定义。
如:
dim
a()
as
integer
'
'
redim
a(100)
2、vb.net中定义数组可以直接赋值。
如:
dim
a()
as
integer
={1,
2,
3,4}
vb.net 怎样创建控件数组?
Dim Str(20) As String '20数据元素
Dim Text(20) As TextBox
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定义控件数组,vb如何创建控件数组
分享网址:http://azwzsj.com/article/hdcice.html