473,403 Members | 2,338 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,403 software developers and data experts.

In Visual C# - How to I determin which Button is pressed.

Here's the deal. I am creating a calculator program using visual studios. I have a much of buttons on my form and I want to be able to determin which button is clicked by the user.

Reason: I want to use the Text property of the botton pressed by the user without have to have a click event for each button.
Nov 9 '07 #1
3 1285
Shashi Sadasivan
1,435 Expert 1GB
Here's the deal. I am creating a calculator program using visual studios. I have a much of buttons on my form and I want to be able to determin which button is clicked by the user.

Reason: I want to use the Text property of the botton pressed by the user without have to have a click event for each button.
Hi
you could have one click event and link that to the click events of all the buttons.
So for the buttons which have numbers, you could use one event for the 10 buttons.

apart from that, you will have to use event handlers (because clicking a button is an event...ding ding)
Nov 9 '07 #2
Plater
7,872 Expert 4TB
You can assign the same handler to multiple buttons.
To tell which button is pressed, the event handler has that "object sender" argument.
That object will represent which button was pressed:
Expand|Select|Wrap|Line Numbers
  1. if (sender.GetType()==typeof(Button))
  2. {//sender is a Button type (like it should be)
  3.    Button TheClickedButton = (Button)sender;
  4.    //now you can access the properties of the button normally
  5.    //TheClickedButton.Text
  6.    //TheClickedButton.Name
  7. }
  8.  
Nov 9 '07 #3
You can assign the same handler to multiple buttons.
To tell which button is pressed, the event handler has that "object sender" argument.
That object will represent which button was pressed:
Expand|Select|Wrap|Line Numbers
  1. if (sender.GetType()==typeof(Button))
  2. {//sender is a Button type (like it should be)
  3.    Button TheClickedButton = (Button)sender;
  4.    //now you can access the properties of the button normally
  5.    //TheClickedButton.Text
  6.    //TheClickedButton.Name
  7. }
  8.  

Thanks. I will give it a shot.
Nov 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: robert | last post by:
hi! I want to have a custom button change appearance when pressed and then call a function and change back to its original appearance when released. here's what i have now, which works mostly....
2
by: jb | last post by:
Hello, I need to know which button was pressed in the submit , i tried reading the vaule of submit it the validateDate function but it returns 'undefined' value ; I do this in asp all the time, Not...
8
by: Syed Ali | last post by:
Hello, I have 1 HTML form with 4 submit buttons and 10 textfield entry areas. If submit button1 is pressed I need to make sure that all 10 textfield entries have been filled before submitting...
3
by: James McGivney | last post by:
I have a project in VS.NET using C# I have a series of buttons on an aspx page. When one of the buttons is pressed, a panel becomes visible and allows the user to enter and edit data. I want to...
18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
0
by: feng | last post by:
I want to use onunload to capture user's action when he clicks on the "x" button, the close window button on the upper-right corner of the brower window, to close the browser. Here is how I...
4
by: Alex | last post by:
Dear colleagues How can I determin if "return button was pressed" in a textbox? I am trying to di this with this methode: Private Sub txbInput_KeyDown(ByVal sender As Object, ByVal e As...
19
by: darrel | last post by:
On my vb.net page, I have 4 sets of inputs + form buttons. example: Search: (GO) Zip: (GO) County: (GO) County: (GO) The problem is if I go to the page, type in a zip code, and hit...
2
by: Chas Large | last post by:
Hi all, I hope I have found the right group to post this question to, if not please point me in the right direction. I have VB.net 2003 and need to make a button that performs an action only...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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
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
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...
0
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...
0
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,...

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.