Click here to Skip to main content
15,877,384 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

is it possible to have one control variable for multiple buttons?

i am creating an onscreen keyboard and need to make each button of a user defined type that is derived from CButton class.

i dont want to make a separate variable for each button for the DrawItem() function to be called.

Helppp!! :(
Updated 17-Aug-11 17:50pm

1 solution

use the sender object to determine which button was pressed.

in your OnClickEvent state:
Button clickedOne = (Button) sender;

You can now access ID or Text properties of the button and do what you want to do
Share this answer
Member 8112150 17-Aug-11 5:55am    
actually i have to set the style of the buttons on the initdialog of the main dialog box.
but these buttons belong to a class that i have derived from CButton class and this class has the
DrawItem() that has the code to set the style.

this is called if i create a control variable for each button. but i have around 26 buttons and i dont want to create 26 control variables :(
Herman<T>.Instance 17-Aug-11 6:00am    
in your method you coould check with a foreach(Control ctrl in Form.Controls) all available controls. If ctrl is Button.... do your styling
Member 8112150 18-Aug-11 0:27am    
Going to try it out..

Thanks a bunch :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900