My form has several numeric up down controls. All of these controls, when changed, call the same method:
private void SetColors(object sender, EventArgs e)
How do I determine which control called the method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That’s what the
senderparameter is for.If you know the time, you can cast it appropriately:
If it could be any of several types, you can use
asand a null test, orisfollowed by a cast.Of course, you only need to cast to the type which contains the members you need – so you could potentially just cast to
Control, for example.EDIT: Suppose you just want the name, and you know that the sender will always be a control of some kind. You can use: