0

how would i go about putting each number button 0-9 into one piece of code and then call it in the click_event

5
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by ddanbe
1

Something like this works ...

private void Form1_Load(object sender, EventArgs e)
        {
            btn0.Click += new EventHandler(ButtonClickHandler);
            btn1.Click += new EventHandler(ButtonClickHandler);
            // etc.
        }

        private void ButtonClickHandler(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn == btn0)
            { 
                // Handle btn0 ...
                // etc.
            }
        }

Edited by viljoed: n/a

0

I would do what viljoed does, but I would put my buttons in an array or a list for easy handling.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.