Re: Power of System.Reflection.Assembly by Jonathan
Jonathan
Fri Jun 03 12:11:03 CDT 2005
I found the solution to list the buttons of the form in ListBox2:
Private Sub ListBox1_SelectedIndexChanged(
ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
Dim t As Type = oAssembly_m.GetType(ListBox1.SelectedItem.ToString())
Dim o As Object
o = Activator.CreateInstance(t)
Dim f As Form = DirectCast(o, Form)
If TypeOf o Is Form Then
ListBox2.Items.Clear()
For Each oControl In f.Controls
ListBox2.Items.Add(oControl.Name)
Next
End If
End Sub
"Jonathan" wrote:
> Ok, the following code list all the classes, modules, delegates of a
> assembly...
>
> Dim a As [Assembly]
> a = LoadFrom("C:\WindowsApplication1.exe")
>
> ListBox1.Items.Clear()
> ListBox1.Items.AddRange(a.GetTypes())
>
> For example, I build a Windows Application with a Form1 with two buttons,
> the previous code list one item in the listbox1:
>
> WindowsApplication1.Form1
>
> I want select this item of the listbox1 and list the two buttons of the
> Form1 in other listbox (ListBox2).
>
>
> "Francisco Padron" wrote:
>
> > Ok. I missundertood your question and I'm not sure I understand it yet.
> >
> > ListBox1.Items.Clear()
> > ListBox1.Items.AddRange(a.GetTypes())
> >
> > This code list all the types in the assembly.
> >
> > Do you want to list the types that derive from Button ? From Control ? What
> > exactly do you want to see in this list ? Class Names ? Property names ?
> > Maybe an example will help.
> >
> > If what you want is to list all the classes in an assembly that derive from
> > control you can do:
> >
> > Assembly a = GetType().Assembly;
> >
> > foreach (Type type in a.GetTypes()) {
> >
> > if (type.IsSubclassOf(typeof(Button)))
> >
> > listBox1.Items.Add(type);
> >
> > }
> >
> >
> > --
> > Francisco Padron
> > www.chartfx.com
> >
> >
> >