PDA

View Full Version : سوال: مشکل در بدست آوردن نام تمام فرم های پروژه به صورت Runtime



pooya1072
چهارشنبه 14 فروردین 1392, 00:53 صبح
سلام
اگه ممکنه به کد های زیر توجه کنید و اگه تونستید بگید مشکل چیه که ارور میده.

Private Sub GetForms()
Dim cAssembly As System.Reflection.Assembly
Dim curType As Type
Dim curTypes() As Type
Dim cFormType As Type
cAssembly = System.Reflection.Assembly.GetExecutingAssembly
cFormType = GetType(System.Windows.Forms.Form)
curTypes = cAssembly.GetTypes
For Each curType In curTypes
If TypeOf (curType) Is cFormType Then
ListBox1.Items.Add(cFormType.Name)
End If
Next
End Sub
ارورش توی خط دهم و متنش به شرح زیره:

Type 'cFormType' is not defined

ولی من cFormType رو بالا به عنوان متغیر از نوع تایپ معرفی کردم !!!!

pooya1072
چهارشنبه 14 فروردین 1392, 13:33 عصر
خب ... جوابش رو بدست آوردم . شاید به دردتون خورد >>>>

Private Sub GetForms()
Dim cAssembly As System.Reflection.Assembly
Dim curType As Type
Dim curTypes() As Type
Dim cFormType As Type
cAssembly = System.Reflection.Assembly.GetExecutingAssembly
cFormType = GetType(System.Windows.Forms.Form)
curTypes = cAssembly.GetTypes
For Each curType In curTypes
If curType.BaseType = cFormType Then
ListBox1.Items.Add(curType.Name)
End If
Next
End Sub
با اجرای این تابع در هنگام اجرا می تونید تمام فرم های موجود در برنامه رو لیست کنید.