-2

请帮助我了解此代码。当用户按下 Enterkey 时,此代码可以运行,但我不知道如何解决这个问题。线问题中的问题。** 我想知道 EnterKey 的 KeyCode

    private void Form1_KeyPress(object sender, KeyPressEventArgs e)
    {
        Button b = new Button();
        b.Text = e.KeyChar.ToString();
        if (panel1.Enabled)
        {
            if (e.KeyChar >= '0' && e.KeyChar <= '9')
            {
                Numbers(b, null);
                foreach (Button c in panel1.Controls)
                {
                    if (c.Text == b.Text)
                    {
                        c.Focus();

                    }
                }
            }
            else
             if (e.KeyChar == 13)
                    btnequal.Focus();

                if (e.KeyChar == '+' || e.KeyChar == '-' || e.KeyChar == '/' || e.KeyChar == '*')
                {
                    Operations(b, null);
                    foreach (Button c in panel1.Controls)
                    {
                        if (c.Text == b.Text)
                        {
                            c.Focus();

                        }
                    }
                }
                else
                    if (e.KeyChar == '.')
                    {
                        btndot_Click(null, null);
                        btndot.Focus();
                    }
                    else
                        if (e.KeyChar == '\b')
                        {
                            btnbackspace_Click(b, null);
                            btnbackspace.Focus();
                        }
                        else
               line problem           ===>  if (e.KeyChar =='\n')
                                MessageBox.Show("you press enter");
        }
4

1 回答 1

2

您可以使用其中任何一个来查看何时按下 Enter/Return 键:

if (e.KeyChar == (char)Keys.Return)
if (e.KeyChar == '\r')
if (e.KeyChar == 13)
if (e.KeyChar == 0x0D)
于 2013-10-30T18:42:13.650 回答