Home All Groups Group Topic Archive Search About

Needto grab the name and position of all buttons on a form -is this possible?

Author
24 Nov 2006 3:57 PM
Marc
Hi,

In order to save user preferences I need to grab the name and position
of all buttons on a form, which i will then save to a text file. Anyone
know how I can easily get this information?

Thanks
Marc

Author
24 Nov 2006 4:05 PM
lord.zoltar
Marc wrote:
> Hi,
>
> In order to save user preferences I need to grab the name and position
> of all buttons on a form, which i will then save to a text file. Anyone
> know how I can easily get this information?
>
> Thanks
> Marc

The form has a Controls property that contains all the controls.
Iterate through that and check certain properties of each control to
see if they are the controls you are looking for.
In this case, you might want to take certain actions if you encounter a
control of type Button while iterating through the Controls.
Author
24 Nov 2006 4:19 PM
Marc
Great...any idea how I access this though?

lord.zol***@gmail.com wrote:
Show quoteHide quote
> Marc wrote:
> > Hi,
> >
> > In order to save user preferences I need to grab the name and position
> > of all buttons on a form, which i will then save to a text file. Anyone
> > know how I can easily get this information?
> >
> > Thanks
> > Marc
>
> The form has a Controls property that contains all the controls.
> Iterate through that and check certain properties of each control to
> see if they are the controls you are looking for.
> In this case, you might want to take certain actions if you encounter a
> control of type Button while iterating through the Controls.
Author
24 Nov 2006 5:12 PM
lord.zoltar
Marc wrote:
> Great...any idea how I access this though?
>

Ok...
First, you've been asking many very basic questions. I think you need
to sit and just read through some basic tutorials or documents. ;)

Now, I'll answer your question ;)
A Form has a property named "Controls". If you have a form named FormA,
you access it by typing "FormA.Controls", or "Me.Controls" if the code
is located in FormA.
"Controls" will return a collection of all the UI controls on the form.
To find all of the buttons on a form, you have to look at the items in
this collection and see which of them are buttons.
You can use the "For Each" loop to do this (I can't explain it all
here, MSDN probably has good documentation on it).
It looks like this:
For each Ctrl As Control in Me.Controls
    if TypeOf Ctrl Is Button then
        'Do some special button-processing code here.
    end if
next

This code represents a loop that looks at each Control in a form's
Controls Collection.
For each of the controls, it check to see if it is a button, and if it
is, you can put your own code in there.
About the syntax:
- "For Each" will iterate through a collection of somethings.
- "Ctrl As Control" will create a new variable named "Ctrl" of type
"Control". "Ctrl" will refer to the object in the collection that is
currently being inspected.
- "in Me.Controls" means you will loop through all of the objects in
"Me.Controls"

Hope this helps.
Author
24 Nov 2006 5:19 PM
Marc
Yes, thats is a big help! I got it working.

I just need to find a way to read the information back in form the text
file


lord.zol***@gmail.com wrote:
Show quoteHide quote
> Marc wrote:
> > Great...any idea how I access this though?
> >
>
> Ok...
> First, you've been asking many very basic questions. I think you need
> to sit and just read through some basic tutorials or documents. ;)
>
> Now, I'll answer your question ;)
> A Form has a property named "Controls". If you have a form named FormA,
> you access it by typing "FormA.Controls", or "Me.Controls" if the code
> is located in FormA.
> "Controls" will return a collection of all the UI controls on the form.
> To find all of the buttons on a form, you have to look at the items in
> this collection and see which of them are buttons.
> You can use the "For Each" loop to do this (I can't explain it all
> here, MSDN probably has good documentation on it).
> It looks like this:
> For each Ctrl As Control in Me.Controls
>     if TypeOf Ctrl Is Button then
>         'Do some special button-processing code here.
>     end if
> next
>
> This code represents a loop that looks at each Control in a form's
> Controls Collection.
> For each of the controls, it check to see if it is a button, and if it
> is, you can put your own code in there.
> About the syntax:
>  - "For Each" will iterate through a collection of somethings.
>  - "Ctrl As Control" will create a new variable named "Ctrl" of type
> "Control". "Ctrl" will refer to the object in the collection that is
> currently being inspected.
>  - "in Me.Controls" means you will loop through all of the objects in
> "Me.Controls"
>
> Hope this helps.