繁体   English   中英

如果输入了无效数字,则显示错误消息

[英]Display an error message if an invalid number is entered

我在 WinForms 中有一个菜单屏幕,其中包含 1-8 的选项。

您可以在下面找到 KeyDown 方法:

        private void Form2_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.D1)
        {
            Form3 f3 = new Form3();
            f3.ShowDialog();
        }

        else if (e.KeyCode == Keys.D2)
        {
            Form4 f4 = new Form4();
            f4.ShowDialog();
        }

        else if (e.KeyCode == Keys.D3)
        {
            Form5 f5 = new Form5();
            f5.ShowDialog();
        }

        (...)

        else if (e.KeyCode == Keys.D8)
        {
            this.Close();
        }
    }

如果输入了无效号码,我应该怎么做才能显示错误消息? 谢谢。

else if要对错误消息执行MessageBox.Show()的话,还有else吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM