扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
Dim Str(20) As String '20数据元素
创新互联-专业网站定制、快速模板网站建设、高性价比九龙坡网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式九龙坡网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖九龙坡地区。费用合理售后完善,10多年实体公司更值得信赖。
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
你这是控件数组?你这明明就是9个不同的 TextBox 控件啊,只不过名字长得像而已。
vb.net和vb6.0不同,无法直接使用控件数组。不过可以通过其他方式变通一下。
比如现在有10个label,要将这10个label的text属性统一设置为“这是第X个标签”(X为1-10)。
1.建立10个label,名称分别为label1、label2、label3。。label10
2.代码:
For i = 1 To 10
Me.FindControl("label" i).Text = "这是第" i “个标签”
Next i
关键点是Me.FindControl()的方法,在代码中Me.FindControl("label1").text与label1.text是一样的。
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"
……
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流