473,661 Members | 2,478 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 1449
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.comwr ote:
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(Ob ject 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...@construct ion-imaging.com wrote:
On Oct 8, 1:09*pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
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(Ob ject 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***@construc tion-imaging.comwrot e:
Private void Common_Click(Ob ject 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...@construct ion-imaging.com wrote:
>On Oct 8, 1:09 pm, Duggi <DuggiSrinivasa ...@gmail.comwr ote:
>>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(Ob ject 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
3132
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 (count = 0; count <= 1; count++) { if (eval(f.RadioButtons.checked)) { btnChosen = true; }
6
11181
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 the radio buttons this way(in a loop): this.groupBox1.Controls.Add(radio); but I can see there only one radio button . How can I see all of them or maybe I should use some kind of radio buttons array first?
10
1588
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 Command1_Click(Index As Integer) Select Case Index
4
4128
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 on each of them. For each of these buttons I do the following after their declaration: AddHandler buttons(row, col).MouseUp, AddressOf buttonclick
2
1802
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 problem is that the application is rather slow at painting the buttons. Ideally I wanted to allow the user to re-size the control and change the text and style of the buttons without such rendering issues. (I have a tool to re-size the buttons,...
1
6876
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 grandtotal the costs ready for the selected items to be inserted back to the database. I did something like this before with Checkboxes, but Radio button have to be named the same to maintain their groupings.
5
13149
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 collection, as if they were an array of radio buttons ? Basically i want to plonk the radio buttons on a panel then use a for loop to index through the radio buttons with an idenex to check thier state. I want to do it this way becasue i want to...
6
2721
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 action buttons, such as "Edit", "Add", and "Comment". Since I do not know how many rows of data will be retrieved - and therefore how many buttons I need - I am using button arrays for each button, like so: echo "<input type=\"submit\"...
3
1278
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 in the gui to an msaccess database with all the information about pricing and what courses the textbooks correlate to. the best way for me to describe it is a row of textboxes for inputs for isbn#, textbook name, the course it correlates to, pricing,...
2
5254
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 duplicate the action in Access. Chuck
0
8855
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
8758
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
8545
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
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5653
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
4179
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...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.