473,890 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing multiple button-properties in a for-loop ?

Dear all,

I've a lot of buttons named button1..button 100 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=Colo r::YellowGreen;
}

to avoid:

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

Many thanks for suggestions,

Wolfgang
Nov 17 '05 #1
5 1332
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**********@y ahoo.de> wrote in message
news:OV******** ******@TK2MSFTN GP14.phx.gbl...
Dear all,

I've a lot of buttons named button1..button 100 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=Colo r::YellowGreen;
}

to avoid:

button1->BackColor = Color::YellowGr een;
button2->BackColor = Color::YellowGr een;
button3->BackColor = Color::YellowGr een;
...
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<Bu tton *>(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******** ******@TK2MSFTN GP12.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**********@y ahoo.de> wrote in message
news:OV******** ******@TK2MSFTN GP14.phx.gbl...
Dear all,

I've a lot of buttons named button1..button 100 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=Colo r::YellowGreen;
}

to avoid:

button1->BackColor = Color::YellowGr een;
button2->BackColor = Color::YellowGr een;
button3->BackColor = Color::YellowGr een;
...
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<Bu tton *>(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******** ******@TK2MSFTN GP12.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**********@y ahoo.de> wrote in message
news:OV******** ******@TK2MSFTN GP14.phx.gbl...
> Dear all,
>
> I've a lot of buttons named button1..button 100 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=Colo r::YellowGreen;
> }
>
> to avoid:
>
> button1->BackColor = Color::YellowGr een;
> button2->BackColor = Color::YellowGr een;
> button3->BackColor = Color::YellowGr een;
> ...
>
>
> 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**********@y ahoo.de>
wrote:
Dear all,

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

System::Window s::Forms::Butto n * Wolfgang;

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

to avoid:

button1->BackColor = Color::YellowGr een;
button2->BackColor = Color::YellowGr een;
button3->BackColor = Color::YellowGr een;
...
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
4728
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
2042
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 scroll-bars work as advertised. That's great. However, if you click the Left Mouse button, it calls code which expands the width of the canvas by 100 pixels. The area being viewed expands correspondingly..... BUT I DON'T WANT IT TO!!
2
1866
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 function to submit the form data. However, it didn't work properly and I changed to use SUBMIT type. <INPUT TYPE="BUTTON" NAME="action1" VALUE="Return to Main Search Page" onClick="action1()">
1
2174
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 what the image looks like, and how big it is. the quality is selected using a trackBar1. the MouseUp event of trackBar1 triggers this method public void updatePanel() string file =...
1
3412
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. Does anyone have any ideas how to "select" multiple headers to sort on (as if it were a datasheet and you select multiple columns, then sort).
1
19333
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> <br><br> <input type="button" value="Select" onClick="go()">&nbsp;&nbsp;&nbsp; <input type="button" value="Cancel" onClick="cancel()"> when user choose any one and click "select" button, the value will be transfered to original window:
1
1287
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 these entries...table name is "TestSuite" ---------- ------- -------- | Initial | Name | ---------- ------- -------- | S | TestSuite1 | -------------------------------
5
7664
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 click again on that same button than it will open same form again in seperate window. But instead of that already open form comes.and so i couldn't open that form multiple times. Already open form must be remain as it is even if I click on that button...
6
6293
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 are still enquiring). Is it possible to dynamically change the base class to something else? Initial experiments appear to show it is not: -------------------------------- snip -------------------------------- pass
14
1982
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
11227
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10812
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10922
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9630
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8016
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7169
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5848
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4676
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4270
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.