niico
asked on
Windows c# app - many buttons, one function - how to tell which button was clicked
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.ToS tring());
-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?
The closest I have got is this:
MessageBox.Show(sender.ToS
-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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks works well.
Im looking for a good book/reference - anything you could recommend?
Im looking for a good book/reference - anything you could recommend?
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 ;-))
ASKER
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...
thanks again...
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.
However, for complex subjects, it's always good to have some background knowledge so that you understand the basics.
ASKER
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?
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?
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.
http://www.intap.net/~drw/cpp/cpp03_03.htm
it's just a simple way of converting one variable type into another.
ASKER
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)
ASKER
-that shows me whats in 'sender' - though as well as the text of the button I get:
System.Windows.Forms.Butto