如何在触发按钮单击事件时使pictureBox可见并更新标签文本?

时间:2017-05-14 11:52:24

标签: c# winforms

希望有人可以帮助解决这个问题。我有一个登录表单,我想让用户知道一旦点击提交按钮,应用程序正在处理他/她的请求。问题是我在表单启动时设置了labe1.TEXT = "";pictureBox2.Visible = false;但是当用户点击时我无法让程序将其设置回label.Text = "processing";pictureBox2.Visible = true;提交按钮。

private void btnLogin_Click_1(object sender, EventArgs e)
{
    AppDomain.CurrentDomain.SetData("DataDirectory", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
    SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\store_close_localdb.mdf;Integrated Security=True;Connect Timeout=30");
    SqlDataAdapter sda = new SqlDataAdapter("Select Role from tblLogin where Username='" + tbUsername.Text + "' and Password='" + tbPassword.Text + "' ", con);
    DataTable dt = new DataTable();
    sda.Fill(dt);
    if (dt.Rows.Count == 1)
    {
        label2.Text ="Processing your login request, please wait...";
        pictureBox2.Visible = true;
        Application.DoEvents();
        pleasewait pw = new pleasewait();
        pw.Show();
    }
    else
    {
        label1.Text = "INCORRECT USERNAME OR PASSWORD :(";
    }
}

0 个答案:

没有答案