Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows c# app - many buttons, one function - how to tell which button was clicked

Posted on 2003-03-09
9
Medium Priority
?
202 Views
Last Modified: 2010-04-15
I have a windows forms app in vs.net / c#. I have 26 buttons - A-Z, rather than have 26 different handlers I would like to have one function then determine which button was pressed (Im going to pass the relevant letter into a stored procedure to a database).

The closest I have got is this:
MessageBox.Show(sender.ToString());

-that shows me whats in 'sender' - though as well as the text of the button I get:


Is there any way I can easily just get what I require?
0
Comment
Question by:niico
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 

Author Comment

by:niico
ID: 8097614
sorry was supposed to read:

-that shows me whats in 'sender' - though as well as the text of the button I get:
System.Windows.Forms.Button, Text: A

0
 
LVL 10

Accepted Solution

by:
smegghead earned 200 total points
ID: 8098599
You have to cast 'sender' back into button.

so...

string ClickedButtonText=((Button)sender).Text;

0
 

Author Comment

by:niico
ID: 8098641
Thanks works well.

Im looking for a good book/reference - anything you could recommend?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:smegghead
ID: 8098672
If you have a look on amazon you'll find lots of books, all with reviews (watch out for the ones that are too positive though.. they're probably written by the author ;-))
0
 

Author Comment

by:niico
ID: 8098692
actually i already have a few books from amazon - it can be hard to find what i need in them though not sure why.

thanks again...
0
 
LVL 10

Expert Comment

by:smegghead
ID: 8098719
Forums like this are a good place to learn.. in my opinion you pick up a lot more by getting your hands dirty and asking questions when you get stuck.

However, for complex subjects, it's always good to have some background knowledge so that you understand the basics.
0
 

Author Comment

by:niico
ID: 8098748
yes indeed - ive learnt a lot from places like this - it always makes me wonder how people learnt this stuff in the first place though :)

Ive got a couple of good books on c#.net but I cant find anything on the windows forms side...

where did you find out about what I asked in this question out of interest?
0
 
LVL 10

Expert Comment

by:smegghead
ID: 8098763
I learned about casting when writing c++ applications. It's the same in c# (as are most things)

http://www.intap.net/~drw/cpp/cpp03_03.htm

it's just a simple way of converting one variable type into another.
0
 

Author Comment

by:niico
ID: 8101745
ok thanks - so casting is basically just converting between datatypes... is there not a more c#ey ToString() type way of doing this as well? (just wondering)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question