コード例 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button obj   = sender as Button;
            string strip = obj.Content.ToString();

            if (strip[0] >= '0' && strip[0] <= '9')
            {
                textbox1.Text = textbox1.Text + strip;
            }
            else if (strip[0] == '-' || strip[0] == '+' || strip[0] == '*' || strip[0] == '/')
            {
                operation     = strip[0];
                ip1           = Convert.ToInt32(textbox1.Text);
                textbox1.Text = "";
            }
            else if (strip[0] == '=')
            {
                ip2           = Convert.ToInt32(textbox1.Text);
                textbox1.Text = "";


                if (operation == '+')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.Add().ToString();
                }
                else if (operation == '-')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.Sub().ToString();
                }
                else if (operation == '*')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.mul().ToString();
                }
                else if (operation == '/')
                {
                    aobj.no1      = ip1;
                    aobj.no2      = ip2;
                    textbox1.Text = aobj.div().ToString();
                }
            }
        }