For Each Control As Windows.Forms.Control In Me.Controls
If Control.GetType Is GetType(Button) Then
Control.Enabled = False
Control.Width = 200
End If
Next
For Each Control As Windows.Forms.Control In Me.Controls
If Control.GetType Is GetType(TextBox) Then
Control.Enabled = False
Control.Width = 200
End If
Next
,etc...
當想取得目前程式中所有被開啟的表單集合時。
For Each frm As Form In My.Application.OpenForms
MsgBox(frm.Name & "," & frm.Text)
Next
之後就可以做你想做的運用了...
存取每個表單上的全域物件(或變數)。
ex:
if frm.Name = "form1" then .....
,etc...
備註:
如果某Control是停駐於另一個Control下
則用此方法會找不到
ex:TextBox1 停駐於 GroupBox1 下...
此時的方法只會顯示(查詢到) GroupBox
可參考 方法 或 更好的方法(待查)
[ASP.NET] 透析FindControl
參考:
[技巧] Controls.Find - 驗證篇
List Of ALL Controls In PROJECT - VB.Net
How to find all child controls from a starting control or form
Foreach Control in form, all the TextBoxes
How to recursively get all controls on a form in C#
How to get ALL child controls of a Windows Forms form
Foreach Every Control on all forms
沒有留言:
張貼留言