如何列出项目所有形式的所有按钮 [英] how to get list all buttons in all forms of the project
本文介绍了如何列出项目所有形式的所有按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有下一个代码可以在 vb.net 中获取项目中的所有表单.
I have the next code to get all forms in the project in vb.net.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim types As Type() = myAssembly.GetTypes()
For Each t As Type In types
If UCase(t.BaseType.ToString) = "SYSTEM.WINDOWS.FORMS.FORM" Then
MessageBox.Show(t.Name)
End If
Next
End Sub
如何获取所有项目表单中所有按钮的列表?
how to get a list of all buttons in all project's form?
推荐答案
Dim formType As Type = Me.GetType().BaseType
Dim forms As List(Of Form) = (From t In Me.GetType().Assembly.GetTypes() Where t.IsSubclassOf(formType) = True Select DirectCast(Activator.CreateInstance(t), Form)).ToList()
For Each f In forms
Dim ctrl As Control = f.GetNextControl(Me, True)
Do Until ctrl Is Nothing
If TypeOf ctrl Is Button AndAlso ctrl.Name <> "cmdClose" Then
ctrl.Enabled = False
End If
ctrl = f.GetNextControl(ctrl, True)
If ctrl Is Nothing Then
GoTo Line1
Else
If ctrl.GetType = GetType(Button) Then
MsgBox(f.Text & " _ " & ctrl.Name)
End If
End If
Line1:
Loop
Next
这篇关于如何列出项目所有形式的所有按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文