vb.net 历遍项目的窗体
答案:1 悬赏:50
解决时间 2021-01-16 02:37
- 提问者网友:温旧梦泪无声
- 2021-01-15 10:48
vb.net 历遍项目的窗体
最佳答案
- 二级知识专家网友:人類模型
- 2021-01-15 11:47
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim TheTypes As Type() = myAssembly.GetTypes()
Dim myType As Type
For Each myType In TheTypes
If myType.BaseType.ToString = "System.Windows.Forms.Form" Then
ListBox1.Items.Add(myType.Name)
End If
Next
End Sub
追问:老师,你的方法很好,如果我要去show listbox1里的某个窗体,怎么做呢?就是用变量的方法,再麻烦你一下了!!谢谢!
追答: Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
If ListBox1.SelectedItem IsNot Nothing Then
Dim MyForms() As Form = {Me, Form2, frmAbout} '按照你自己的窗体名称定义数组
For i = 0 To MyForms.Length - 1
If MyForms(i).Name = ListBox1.SelectedItem.ToString AndAlso Not MyForms(i).Visible Then
MyForms(i).Show()
End If
Next
End If
End Sub
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim TheTypes As Type() = myAssembly.GetTypes()
Dim myType As Type
For Each myType In TheTypes
If myType.BaseType.ToString = "System.Windows.Forms.Form" Then
ListBox1.Items.Add(myType.Name)
End If
Next
End Sub
追问:老师,你的方法很好,如果我要去show listbox1里的某个窗体,怎么做呢?就是用变量的方法,再麻烦你一下了!!谢谢!
追答: Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
If ListBox1.SelectedItem IsNot Nothing Then
Dim MyForms() As Form = {Me, Form2, frmAbout} '按照你自己的窗体名称定义数组
For i = 0 To MyForms.Length - 1
If MyForms(i).Name = ListBox1.SelectedItem.ToString AndAlso Not MyForms(i).Visible Then
MyForms(i).Show()
End If
Next
End If
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息