将登录表单与Form2链接 [英] Linking Login form with Form2

查看:68
本文介绍了将登录表单与Form2链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,其中包含用户ID&用户输入的密码。只有两个字段都正确才能指向下一个表格。即使其中一个字段错误,它也应显示一个消息框,说明特定字段不正确。我的代码的一部分如下所示。但它不起作用。



I have a login form which contains an user id & password to be entered by the user. Only if both fields are correct should it direct to next form. Even if one of the field is wrong, it should display a message box saying the particular filed is incorrect. A part of my code is as given below. But it is not working.

private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.txt = "USER" && textBox2.txt = "password123")
            {
                this.Hide();
                Form2 PROJ_FORM1 = new Form2();
                PROJ_FORM1.Show();
            }
            else  if (textBox1.txt != "USER" && textBox2.txt = "password123")
                MessageBox.Show("Incorrect User Id");
            else  if (textBox1.txt = "USER" && textBox2.txt != "password123")
                MessageBox.Show("Incorrect Password");
            else  if (textBox1.txt != "USER" && textBox2.txt != "password123") 
                MessageBox.Show("Incorrect User Id and Password");
        }

推荐答案

你不应该得到一个属性textBox1.txt而不是textBox1.Text.however

=是赋值运算符,其中in ==用于比较相等运算符。并使用
You should not get a property textBox1.txt instead textBox1.Text.however
= is assignment operator where in == is for compare equality operator.And use
string.Compare()

比较你不应该使用的字符串==来比较像这样的字符串

。但是下面是你的



to compare string you should not use == to compare string like this
.However below is your

private void button1_Click(object sender, EventArgs e)
{
    if (string.Compare(textBox1.Text,"USER")==0 && string.Compare(textBox2.Text,"password123")==0)
    {
        this.Hide();
        Form2 PROJ_FORM1 = new Form2();
        PROJ_FORM1.Show();
    }
    else if (string.Compare(textBox1.Text, "USER") != 0 && string.Compare(textBox2.Text,"password123")==0)
        MessageBox.Show("Incorrect User Id");
    else if (string.Compare(textBox1.Text, "USER") == 0 && string.Compare(textBox2.Text,"password123")!=0)
        MessageBox.Show("Incorrect Password");
    else if (string.Compare(textBox1.Text,"USER")!=0 && string.Compare(textBox2.Text,"password123")!=0)
        MessageBox.Show("Incorrect User Id and Password");
}


这篇关于将登录表单与Form2链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆