Dim Str(20) As String '20數(shù)據(jù)元素
創(chuàng)新互聯(lián)-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比九龍坡網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式九龍坡網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋九龍坡地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴(lài)。
Dim Text(20) As TextBox
Dim n As Integer = 0
For Each i In Text
i = New TextBox '實(shí)例化
i.Location = New Point(50, n * 20)
Me.Controls.Add(i) '添加窗體
Dim Index As Integer = i.TabIndex '沒(méi)index屬性
Str(n) = Index
i.Text = Str(n) 'str數(shù)組值賦值給文本框
n += 1
Next
你這是控件數(shù)組?你這明明就是9個(gè)不同的 TextBox 控件啊,只不過(guò)名字長(zhǎng)得像而已。
vb.net和vb6.0不同,無(wú)法直接使用控件數(shù)組。不過(guò)可以通過(guò)其他方式變通一下。
比如現(xiàn)在有10個(gè)label,要將這10個(gè)label的text屬性統(tǒng)一設(shè)置為“這是第X個(gè)標(biāo)簽”(X為1-10)。
1.建立10個(gè)label,名稱(chēng)分別為label1、label2、label3。。label10
2.代碼:
For i = 1 To 10
Me.FindControl("label" i).Text = "這是第" i “個(gè)標(biāo)簽”
Next i
關(guān)鍵點(diǎn)是Me.FindControl()的方法,在代碼中Me.FindControl("label1").text與label1.text是一樣的。
Imports?System.Text
Imports?System.Windows
Imports?System.Windows.Forms
Public?Class?Netin?'類(lèi)?名
'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?=?"菜單項(xiàng)1"?????
'設(shè)置并添加相關(guān)控件,(窗體)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("你按了鼠標(biāo)")
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"
……