十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
我是VB.Net 2010,你看看能行不。
为琼山等地区用户提供了全套网页设计制作服务,及琼山网站建设行业解决方案。主营业务为做网站、网站制作、琼山网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
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
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
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点抗 ponents = New ComponentModel.Container()
Dim resources As ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(bjt))
Me.TextBox1 = New TextBox(Me点抗 ponents)
Me.Button1 = New Button(Me点抗 ponents)
'For … Next
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.m = New ContextMenuStrip(Me点抗 ponents)
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点虐 中没有控件数组的说法。
替代方法:
·创建一个控件的类型数组: Button[],将所有的button控件创建好后存进去,可以遍历它;
·或将所有要遍历的控件放在一个容器如Panel中,以后遍历这个容器的子控件即可。
----------
你的情况,推荐放在容器中。比如下面就是一个遍历容器的控件,然后找出所有的文本框并修改内容的程序:
//pn 是个 Panel 控件
foreach (Control item in pn.Controls)
{
if (typeof(TextBox) == item.GetType())
{
((TextBox)item).Text = "我是动态修改的!";
}
}