473,511 Members | 16,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array of buttons

I have an array of buttons. There is a common Click-method for these
buttons.
How can I find what button is clicked?

Sauli
Oct 8 '08 #1
6 1446
On Oct 8, 10:01*am, saulij <sau...@hotmail.comwrote:
I have an array of buttons. There is a common Click-method for these
buttons.
How can I find what button is clicked?

Sauli
In the event handler, first arg would be "object sender". you can
identify the sender through this argument. (I believe so)

-Cnu
Oct 8 '08 #2
On Oct 8, 1:09*pm, Duggi <DuggiSrinivasa...@gmail.comwrote:
On Oct 8, 10:01*am, saulij <sau...@hotmail.comwrote:
I have an array of buttons. There is a common Click-method for these
buttons.
How can I find what button is clicked?
Sauli

In the event handler, first arg would be "object sender". you can
identify the sender through this argument. (I believe so)
I haven't tried this but it should work.

Private void Common_Click(Object sender, EventArgs e)
{
Button btn = (Button)sender;
switch (btn.Name)
{
case "btnButton1":
Do something for button1;
break;
case "btnButton2":
Do something for button2;
break;
etc ...
}
}
Oct 8 '08 #3
On Oct 8, 10:42*am, za...@construction-imaging.com wrote:
On Oct 8, 1:09*pm, Duggi <DuggiSrinivasa...@gmail.comwrote:
On Oct 8, 10:01*am, saulij <sau...@hotmail.comwrote:
I have an array of buttons. There is a common Click-method for these
buttons.
How can I find what button is clicked?
Sauli
In the event handler, first arg would be "object sender". you can
identify the sender through this argument. (I believe so)

I haven't tried this but it should work.

Private void Common_Click(Object sender, EventArgs e)
{
* * Button btn = (Button)sender;
* * switch (btn.Name)
* * {
* * * * case "btnButton1":
* * * * * * Do something for button1;
* * * * * * break;
* * * * case "btnButton2":
* * * * * * Do something for button2;
* * * * * * break;
* * * * etc ...
* * }

}- Hide quoted text -

- Show quoted text -
nice to see some code here. The same approach I was suggesting.

Saulij, Please let us know if it solves your issue.

-Cnu
Oct 8 '08 #4
On Wed, 08 Oct 2008 10:42:40 -0700, <za***@construction-imaging.comwrote:
Private void Common_Click(Object sender, EventArgs e)
{
Button btn = (Button)sender;
switch (btn.Name)
{
case "btnButton1":
Do something for button1;
break;
case "btnButton2":
Do something for button2;
break;
etc ...
}
}
Zack's suggestion should work fine (assuming you get the buttons names
correct, of course).

That said, the general approach suggests that the buttons shouldn't in
fact have a common handler. If there's some functionality that should be
shared among the buttons, but they otherwise have button-specific
behavior, then it would probably be better to create individual handlers
for each button, and a method shared among those handlers to deal with the
common functionality.

Pete
Oct 8 '08 #5
Also, you could set the Tag property for each button and use that to identify
them.
Oct 8 '08 #6
Duggi kirjoitti:
On Oct 8, 10:42 am, za...@construction-imaging.com wrote:
>On Oct 8, 1:09 pm, Duggi <DuggiSrinivasa...@gmail.comwrote:
>>On Oct 8, 10:01 am, saulij <sau...@hotmail.comwrote:
I have an array of buttons. There is a common Click-method for these
buttons.
How can I find what button is clicked?
Sauli
In the event handler, first arg would be "object sender". you can
identify the sender through this argument. (I believe so)
I haven't tried this but it should work.

Private void Common_Click(Object sender, EventArgs e)
{
Button btn = (Button)sender;
switch (btn.Name)
{
case "btnButton1":
Do something for button1;
break;
case "btnButton2":
Do something for button2;
break;
etc ...
}

}- Hide quoted text -

- Show quoted text -

nice to see some code here. The same approach I was suggesting.

Saulij, Please let us know if it solves your issue.

-Cnu
This works fine, Thanks a lot

sauli
Oct 13 '08 #7

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

Similar topics

5
3117
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
6
11170
by: juli | last post by:
Hello, I need a control which will contain radio buttons that will be added in a loop. I am using this control a source of some other control. I tried to use group box windows control and to add...
10
1582
by: Tor Inge Rislaa | last post by:
Creating Control Array How to create an array of buttons, with common procedures based on the index of the control. How would this Example from VB 6.0 be in VB.NET? Private Sub...
4
4118
by: Tombatore | last post by:
hello people, I've created an array of buttons by code to have an array : buttons(size, size) I am programming a version of mine sweeper, and one button is a clickable rectangle with an image...
2
1799
by: Carl Gilbert | last post by:
Hi I am developing a custom on screen keyboard. So far I have an array of buttons and then using SendKeys to send the text of the button to the active control to receive the text. The only...
1
6845
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
5
13136
by: Peted | last post by:
I know you can iterate through a collection of radio buttons in a panel, using a "for each in control" type iteration that c# supports, but is it possible to iterate through the radio buttons...
6
2712
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
3
1259
by: captainphoenix | last post by:
vb 2005 what i have is an interface designed to act like an order form at a bookstore, like the one a clerk would use to ring up a customer for books. The btnList button connects all the textboxes...
2
5249
by: Chuck | last post by:
How can I make an array of command buttons (or toggle buttons) on a form and have a text box on the same form display the index of the button clicked? This works very well in VB6, but I can't...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7355
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,...
0
7423
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...
1
7081
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...
1
5066
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...
0
4737
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...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.