Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 文本框中的按键不工作_C# 4.0_Key - Fatal编程技术网

C# 4.0 文本框中的按键不工作

C# 4.0 文本框中的按键不工作,c#-4.0,key,C# 4.0,Key,我试图让下面的代码工作,但没有用 我必须创建一个登录窗口,除了从登录按钮按输入键输入密码文本框,结果是相同的。2010年 您应该使用键控事件,它在您的情况下更可靠。 然后检查有无按键。 e、 g: 另一方面:我真的不鼓励您使用登录方法,将字符串与硬编码字符串进行比较确实是一种浪费,特别是在您有多个用户的环境中,有更好的方案,否则为什么您需要登录 private void button1_Click(object sender, EventArgs e) {

我试图让下面的代码工作,但没有用

我必须创建一个登录窗口,除了从
登录
按钮按
输入
键输入密码文本框,结果是相同的。2010年


您应该使用键控事件,它在您的情况下更可靠。 然后检查有无按键。 e、 g:


另一方面:我真的不鼓励您使用登录方法,将字符串与硬编码字符串进行比较确实是一种浪费,特别是在您有多个用户的环境中,有更好的方案,否则为什么您需要登录

private void button1_Click(object sender, EventArgs e)
        {
            int ok=0;
            if (textBox1.Text == "administrator" && textBox2.Text == "administrator")
            {
                ok = 1;
                this.Hide();
                Admin admin = new Admin();
                admin.ShowDialog();
            }
            if (textBox1.Text == "jucator" && textBox2.Text == "jucator")
            {
                ok = 1;
                this.Hide();
            }
            if (ok == 0)
            {
                label2.Text = "nume user sau parola incorecta";
                label2.Visible = true;
            }

        }
        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(this, new EventArgs());
            }
        }
    private void textBox2_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Enter)
        {
            //DoLogin... in your case it would be 
            button1_Click(null,null);
            e.Handled = true;
        }
        else
        {
            e.Handled = false;
        }
    }