-2
請幫我瞭解這段代碼。 此代碼可以運行時,用戶按Enterkey 但我不知道如何解決這個問題。 問題在線問題。 **我想知道EnterKey任何人都可以在C#中幫助計算器代碼?
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");
}
http://msdn.microsoft.com/en -us/library/ms752054.aspx – mbeckish
可能重複[在C#中輸入按鍵](http://stackoverflow.com/questions/12318164/enter-key-press-in-c-sharp) – mbeckish