473,378 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Changing multiple button-properties in a for-loop ?

Dear all,

I've a lot of buttons named button1..button100 and want to change some of there propertys.
Maintaining the overview I'm looking for a possibility for something like:

System::Windows::Forms::Button * Wolfgang;

for (i=1;i<100;i++)
{
Wolfgang = ???;
Wolfgang->BackColor=Color::YellowGreen;
}

to avoid:

button1->BackColor = Color::YellowGreen;
button2->BackColor = Color::YellowGreen;
button3->BackColor = Color::YellowGreen;
....
But I don't know how to fill the gap ??? with code.

Many thanks for suggestions,

Wolfgang
Nov 17 '05 #1
5 1307
Hi,

One thing you can do is to iterate through all the parent's controls,
attempt to cast each control to a Button and if it is a button, change its
colour. You could put your 100 buttons on their own Panel to make this
easier - then all the Panel's Controls will be Buttons.

Steve

"Wolfgang" <wo**********@yahoo.de> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
Dear all,

I've a lot of buttons named button1..button100 and want to change some of
there propertys.
Maintaining the overview I'm looking for a possibility for something like:

System::Windows::Forms::Button * Wolfgang;

for (i=1;i<100;i++)
{
Wolfgang = ???;
Wolfgang->BackColor=Color::YellowGreen;
}

to avoid:

button1->BackColor = Color::YellowGreen;
button2->BackColor = Color::YellowGreen;
button3->BackColor = Color::YellowGreen;
...
But I don't know how to fill the gap ??? with code.

Many thanks for suggestions,

Wolfgang

Nov 17 '05 #2
Hello Steve,

Yes, that was also my suggestion but it leads to something like:

counter = dynamic_cast<Button *>(Pad->Controls->Item[i]);

where I fetch the Button in the "counter"-variable.

Then I must decide if it's one of the Buttons I want to change (unfortunately you where right. I've

also Buttons A..Z which are not affected).

(O.k. I know I could use the tag-property for that)

and then change the property I want.

But for me it seems like searching for things I KNOW.

I know I want to change the Buttons named button1..100.

Hence I thought there would be a possibility to fetch

the button using it's name like button("button1");

Where I can change the string and get the according button.

But thanks for your suggestions.

Wolfgang

P.S.: If someone has a more elegant way than grouping the buttons

which belong together in a pannel to fetch them like described above

I'm still interested.

------------------------------------------------------------------------

"Steve McLellan" <sjm AT fixerlabs DOT com> schrieb im Newsbeitrag news:#o**************@TK2MSFTNGP12.phx.gbl...
Hi,

One thing you can do is to iterate through all the parent's controls,
attempt to cast each control to a Button and if it is a button, change its
colour. You could put your 100 buttons on their own Panel to make this
easier - then all the Panel's Controls will be Buttons.

Steve

"Wolfgang" <wo**********@yahoo.de> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
Dear all,

I've a lot of buttons named button1..button100 and want to change some of
there propertys.
Maintaining the overview I'm looking for a possibility for something like:

System::Windows::Forms::Button * Wolfgang;

for (i=1;i<100;i++)
{
Wolfgang = ???;
Wolfgang->BackColor=Color::YellowGreen;
}

to avoid:

button1->BackColor = Color::YellowGreen;
button2->BackColor = Color::YellowGreen;
button3->BackColor = Color::YellowGreen;
...
But I don't know how to fill the gap ??? with code.

Many thanks for suggestions,

Wolfgang


Nov 17 '05 #3
Hi,

You might be able to do what you suggest you'd need to use reflection. I've
not got any experience doing that, unfortunately. You might be able to use a
regex to match the text on the buttons, if they have similar labels. You
might also want to think about redesigning things - having >100 controls on
a single parent control seems a bit unnecessary, esp if they're unconnected
to other things. You can easily use the interface designer to add them to an
invisible control and add that control to the current parent.

Hope someone can give you some more hope, good luck!

Steve

Yes, that was also my suggestion but it leads to something like:

counter = dynamic_cast<Button *>(Pad->Controls->Item[i]);

where I fetch the Button in the "counter"-variable.

Then I must decide if it's one of the Buttons I want to change
(unfortunately you where right. I've

also Buttons A..Z which are not affected).

(O.k. I know I could use the tag-property for that)

and then change the property I want.

But for me it seems like searching for things I KNOW.

I know I want to change the Buttons named button1..100.

Hence I thought there would be a possibility to fetch

the button using it's name like button("button1");

Where I can change the string and get the according button.

But thanks for your suggestions.

Wolfgang

P.S.: If someone has a more elegant way than grouping the buttons

which belong together in a pannel to fetch them like described above

I'm still interested.

------------------------------------------------------------------------

"Steve McLellan" <sjm AT fixerlabs DOT com> schrieb im Newsbeitrag
news:#o**************@TK2MSFTNGP12.phx.gbl...
Hi,

One thing you can do is to iterate through all the parent's controls,
attempt to cast each control to a Button and if it is a button, change
its
colour. You could put your 100 buttons on their own Panel to make this
easier - then all the Panel's Controls will be Buttons.

Steve

"Wolfgang" <wo**********@yahoo.de> wrote in message
news:OV**************@TK2MSFTNGP14.phx.gbl...
> Dear all,
>
> I've a lot of buttons named button1..button100 and want to change some
> of
> there propertys.
> Maintaining the overview I'm looking for a possibility for something
> like:
>
> System::Windows::Forms::Button * Wolfgang;
>
> for (i=1;i<100;i++)
> {
> Wolfgang = ???;
> Wolfgang->BackColor=Color::YellowGreen;
> }
>
> to avoid:
>
> button1->BackColor = Color::YellowGreen;
> button2->BackColor = Color::YellowGreen;
> button3->BackColor = Color::YellowGreen;
> ...
>
>
> But I don't know how to fill the gap ??? with code.
>
> Many thanks for suggestions,
>
> Wolfgang
>
>


Nov 17 '05 #4
On Wed, 17 Nov 2004 17:10:58 +0100, "Wolfgang" <wo**********@yahoo.de>
wrote:
Dear all,

I've a lot of buttons named button1..button100 and want to change some of there propertys.
Maintaining the overview I'm looking for a possibility for something like:

System::Windows::Forms::Button * Wolfgang;

for (i=1;i<100;i++)
{
Wolfgang = ???;
Wolfgang->BackColor=Color::YellowGreen;
}

to avoid:

button1->BackColor = Color::YellowGreen;
button2->BackColor = Color::YellowGreen;
button3->BackColor = Color::YellowGreen;
...
But I don't know how to fill the gap ??? with code.


Put the buttons in an array (perhaps when you create them), and
iterate over that array.

Tom
Nov 17 '05 #5
That sounds interesting,
Thanks for that idea - I'll have a try.

Wolfgang

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michael nieuwenhuizen | last post by:
how do i create a sticky form with multiple fields? say i want a form with: name: address: country: and if a user presses the submit button it will show
0
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
2
by: Matt | last post by:
The ASP page has multiple buttons, and when the user clicks different buttons, it will submit the form data to different URLs. My first approach was to use BUTTON type, and triggers javascript...
1
by: Sean | last post by:
i am writing a class that visual demonstrates the result of changing the quality of a jpeg. the intention is to do this by saving the file and a selected quality, then reloading it to get an idea of...
1
by: John | last post by:
(acc2002) I have a (continuous) subform (not datasheet) designed to look like columns of data. On each column "header" is a command button that when pressed, sort the records via that field. ...
1
by: ykong1214 | last post by:
In my project, there is a single select tag, <html:select property="userName" size="7"> <html:options collection="UserList" property="value" labelProperty="label" /> </html:select> ...
1
by: rag84dec | last post by:
Hi, I have an asp code which creates a grid or matrics (5 x 5 matrics).Each cell contains a button which will have an initial .The initial will be read from a database. say the database has...
5
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
6
by: Adam C. | last post by:
We have a situation where we want a Swig-generated Python class to have a different base (not object). It doesn't appear that we can coerce Swig into generating the class we want at present (but we...
14
by: Jeff | last post by:
Let's say we have this: <div class="some_class some_other_class"> Is it possible to change *one* of the classnames. Jeff
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.