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

M

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
 
L

lord.zoltar

Marc said:
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.
 
M

Marc

Great...any idea how I access this though?

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

lord.zoltar

Marc said:
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.
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top