Prime b

Prime b

  • NA
  • 810
  • 347k

Question about keyPress

Apr 2 2012 8:42 PM
This is the program i made, my question is for the highlighted parts

Is there any way to get it display automatically? For example when you double click textbox it will create a method  ===>>> private void textBox1_TextChanged(object sender, EventArgs e)
But what about KeyPress? Is there any way to get that method? Do i have to maybe triple click it? I had to write it out my self, so that's what I am wondering.

Also  System.Windows.Forms.KeyPressEventArgs  is the same thing as KeyPressEventArgs?









       private void textBox1_KeyPress(object sender,System.Windows.Forms.KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !(Char.IsControl(e.KeyChar)))
            {
                if(!(e.KeyChar.ToString() == ",") && (textBox1.Text.IndexOf(",") == -1))
                e.Handled = true;
            }

        }

        private void textBox2_KeyPress(object sender,System.Windows.Forms.KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !(Char.IsControl(e.KeyChar)))
            {
                if (!(e.KeyChar.ToString() == ",") && (textBox1.Text.IndexOf(",") == -1))
                    e.Handled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double rate;
            double usd;
            double rub;

            label4.Text = "";

            try
            {
                usd = System.Convert.ToDouble(textBox1.Text);
                rate = System.Convert.ToDouble(textBox2.Text);

                rub = usd * rate;
                label4.Text = usd.ToString("N") + " USD = " + rub.ToString("C");
            }
            catch
            {
                if ((textBox1.Text == "") || (textBox2.Text == ""))
                {
                    MessageBox.Show("Error in output. \n" + "You must enter data in both text boxes.", "Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Error in output. \n" + "Data is in the wrong format in one of the text boxes.", "Converter", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

Answers (2)