大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Public Sub GetAllControls(ByVal InContainer As Control, ByRef RecieveList As ListBox)
创新互联是一家专注于网站建设、网站制作与策划设计,蚌山网站建设哪家好?创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:蚌山等地区。蚌山做网站价格咨询:028-86922220
For i As Integer = 0 To InContainer.Controls.Count - 1
If InContainer.Controls.Item(i).Text "" Then
GetList.Items.Add(InContainer.Controls.Item(i).Text vbCrLf)
End If
If InContainer.Controls.Item(i).Controls.Count 0 Then
GetAllControls(InContainer.Controls.Item(i), GetList)
End If
Next
End Sub
这段代码可行,但不能遍历菜单和工具栏,要按需要修改
for each是用来简化for的,但你这种写法有点奇怪,一般没这样用的,通常的用法是
dim a() as string={....}
dim str as string '定义临时变量,它的类型与你数组中元素类型一致
For Each str In a
MessageBox.Show(str)
Next
你上面代码中,a就是一个3个元素的数组,从a[0]到a[2], 用for each的时候,就会遍历你的a数组,上面的代码相当于
for i=0 to a.Length-1
MessageBox.Show(a(i))
next
Public Sub ReSetText(Control ctrl)
Dim ct As Control
For Each ct In ctrl.Controls
Try
For Each ct2 As Control In ct.Controls
ReSetText(ct2)
Next
Catch
End Try
If (TypeOf ct Is TextBox) Then
ct.Text = ""
ElseIf (TypeOf ct Is ComboBox) Then
Dim cb As System.Windows.Forms.ComboBox = DirectCast(ct, System.Windows.Forms.ComboBox)
cb.SelectedIndex = -1
End If
Next
End Sub
因为textbox在窗体里的panel里,你只遍历窗体的控件是不够的。
For Each i As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
Next