PDA

View Full Version : سوال: پیدا کردن نام تمام فرم های پروژه



davoodrm666_666
دوشنبه 09 دی 1387, 09:35 صبح
سلام آقا آیا میشه از طریق کد نام فرم های برناممون رو بدست بیاریم

samispeed
دوشنبه 09 دی 1387, 10:36 صبح
این کلاسی که نام فرم ها را در برنامه بر می گرداند



Imports System.Reflection
Public Class clsForms
Public Function ReturnForms() As List(Of Form)
Dim myforms As New List(Of Form)
Dim types As Type() = Assembly.GetExecutingAssembly().GetTypes()
For Each type As Type In types
Dim baseType As Type = type.BaseType
Dim name As String = type.FullName
While (Not baseType Is Nothing)
If baseType.Equals(GetType(Form)) Then
myforms.Add(Assembly.GetExecutingAssembly().Create Instance(name))
Exit While
End If
baseType = baseType.BaseType
End While
Next
ReturnForms = myforms
End Function
End Class

برای دسترسی هم می تونید از کد زیر استفاده کنید


Dim cform As New clsForms()
For Each myform As Form In cform.ReturnForms()
...
Next

در ضمن اینجا فقط آقایون عضو نیستند