Программирование - это просто
Advertisement
arrow arrow Visual C# arrow Visual C# . 14. "".
07.02.2023 .
1:
C#
Delphi
Web-
Excel-
.
Visual C# . 14. "". E-mail
megabax   
07.06.2012 .
Delphi

Visual C# . 14. "".

.

C# . , , :

Visual C#  .  14.   "".

"+":

        private void button1_Click(object sender, EventArgs e)

        {

            label1.Text = (sender as Button).Text;

        }

"-", "*","/".  :

Visual C#  .  14.   "".

, , Click :

Visual C#  .  14.   "".

"=":

        private void button5_Click(object sender, EventArgs e)

        {

            double x = 0;

            double x1;

            double x2;

            if (!double.TryParse(textBox1.Text, out x1) || !double.TryParse(textBox2.Text, out x2))

            {

                label2.Text = "ERROR";

                return;

            }

            else

            {

                switch (label1.Text[0])

                {

                    case '+':

                        x = x1 + x2; break;

                    case '-':

                        x = x1 - x2; break;

                    case '*':

                        x = x1 * x2; break;

                    case '/':

                        x = x1 / x2; break;

                }

                label2.Text = "= " + x;

            }

        }

. "+","-","*" "/" , , , . ( , ), sender.

. , , . - "&":

Visual C#  .  14.   "".

:

Visual C#  .  14.   "".

, , - .

, , "=":

        private void button5_Click(object sender, EventArgs e)

        {

            double x = 0;

            double x1;

            double x2;

            if (!double.TryParse(textBox1.Text, out x1) || !double.TryParse(textBox2.Text, out x2))

            {

                label2.Text = "ERROR";

                return;

            }

            else

            {

                switch (label1.Text[1])

                {

                    case '+':

                        x = x1 + x2; break;

                    case '-':

                        x = x1 - x2; break;

                    case '*':

                        x = x1 * x2; break;

                    case '/':

                        x = x1 / x2; break;

                }

                label2.Text = "= " + x;

            }

        }

. , , :

        private void button1_Click(object sender, EventArgs e)

        {

            label1.Text = (sender as Button).Text;

            label2.Text = "=";

        }

. :

        private void textBox1_TextChanged(object sender, EventArgs e)

        {

            label2.Text = "=";

        }

, KeyPress:

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)

        {

            char c = e.KeyChar;

            char sep = Application.CurrentCulture.NumberFormat.CurrencyDecimalSeparator[0];

            switch (c)

            {

                case '+':

                    button1_Click(button1, null); break;

                case 'x':

                case '*':

                    button1_Click(button3, null); break;

                case '-':

                    button1_Click(button2, null); break;

                case '/':

                    button1_Click(button4, null); break;

            }

            e.Handled = !(char.IsDigit(c) || c == sep || c == '-' || c == '\b');

        }

.

, :

Visual C#  .  14.   "".

: "=" ( ). , Form1_KeyPress:

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)

        {

            char c = e.KeyChar;

            char sep = Application.CurrentCulture.NumberFormat.CurrencyDecimalSeparator[0];

            switch (c)

            {

                case '+':

                    button1_Click(button1, null); break;

                case 'x':

                case '*':

                    button1_Click(button3, null); break;

                case '-':

                    button1_Click(button2, null); break;

                case '/':

                    button1_Click(button4, null); break;

                case '=':

                    button5_Click(button5, null); break;

            }

            e.Handled = !(char.IsDigit(c) || c == sep || c == '-' || c == '\b');

        }

 


, *,   "Microsoft Visual Studio 2010 Professional", Microsoft.. 


 

 

()

 

( 12.02.2014 . )
 
« .   . »
 
© 2023 Программирование - это просто
Joomla! - , GNU/GPL.
© 2005-2008 Joom.Ru - Joomla!
Design by Mamboteam.com | Powered by Mambobanner.de
  .