I need to know if I can to list the objects of a form with the namespace
system.reflection.asembly.

For example, I need list all the buttons of the form.

Thanks for help.

Re: Power of System.Reflection.Assembly by Francisco

Francisco
Sat May 21 18:39:33 CDT 2005

You don't need to use reflection for this.

If you want to get all the buttons from a form you can do:

foreach (Control control in form.Controls) {
if (control is Button) {
Button button = (Button) control;
// Here you have a button
}
}

If you have nested controls, you may want to do a recursive call whenever
you find a ContainerControl.

--
Francisco Padron
www.chartfx.com


"Jonathan" <Jonathan@discussions.microsoft.com> wrote in message
news:5E5C26F5-801A-4A13-8193-4014006B3AB6@microsoft.com...
>I need to know if I can to list the objects of a form with the namespace
> system.reflection.asembly.
>
> For example, I need list all the buttons of the form.
>
> Thanks for help.



Re: Power of System.Reflection.Assembly by Jonathan

Jonathan
Mon May 23 10:01:08 CDT 2005

I find code in Internet for to list the members of a assembly (file .dll or
.exe):

dim a As [Assembly]

a = LoadFrom("C:\file.dll")

ListBox1.Items.Clear()
ListBox1.Items.AddRange(a.GetTypes())

This code list all the forms, user controls, reports, etc of the assembly in
a listbox... I want to list in other listbox the buttons of a selected type
in ListBox1:

Dim t As Type = a.GetType(ListBox1.SelectedItem.ToString())

ListBox2.Items.Clear()
ListBox2.Items.AddRange(t.GetMembers)

But GetMembers returns the variables, I need a function that returns the
controls.

"Francisco Padron" wrote:

> You don't need to use reflection for this.
>
> If you want to get all the buttons from a form you can do:
>
> foreach (Control control in form.Controls) {
> if (control is Button) {
> Button button = (Button) control;
> // Here you have a button
> }
> }
>
> If you have nested controls, you may want to do a recursive call whenever
> you find a ContainerControl.
>
> --
> Francisco Padron
> www.chartfx.com
>
>
> "Jonathan" <Jonathan@discussions.microsoft.com> wrote in message
> news:5E5C26F5-801A-4A13-8193-4014006B3AB6@microsoft.com...
> >I need to know if I can to list the objects of a form with the namespace
> > system.reflection.asembly.
> >
> > For example, I need list all the buttons of the form.
> >
> > Thanks for help.
>
>
>

Re: Power of System.Reflection.Assembly by Francisco

Francisco
Mon May 23 12:12:50 CDT 2005

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



Re: Power of System.Reflection.Assembly by Jonathan

Jonathan
Mon May 23 13:37:03 CDT 2005

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
>
>
>

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
> >
> >
> >