I want to make "for exp " 'metro progress spinner' visible on the form while the app is checking the tbl_login in the database for username and password, how can i do sth like this to make WPF elementhost or winform control visible in the form while connecting and looking in database.
here is my code:
private void metroButton1_Click(object sender, EventArgs e)
{
clss_link._User = txtbx_user.Text;
if (txtbx_user.Text == "" || txtbx_pass.Text == "")
{
DialogResult result1;
result1 = MetroFramework.MetroMessageBox.Show(this, "Enter both Username and Password!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
model1.DB_PrjMgntEntities DB = new model1.DB_PrjMgntEntities();
var query = from r in DB.tbl_login
where r.Username == txtbx_user.Text &&
r.Password == txtbx_pass.Text
select r;
if (query.Count() == 1)
{
System.Threading.Thread.Sleep(3000);
frm_main mainFrm = new frm_main();
mainFrm.Show();
this.Hide();
}
else
{
DialogResult result;
result = MetroFramework.MetroMessageBox.Show(this, "Invalid Username or Password!", "Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (result == System.Windows.Forms.DialogResult.Retry)
{
txtbx_pass.Clear();
txtbx_user.Clear();
}
else
{
this.Close();
}
}
}
}
private void metroCheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (metroCheckBox1.Checked == true)
{
txtbx_pass.UseSystemPasswordChar = false;
}
else
{
txtbx_pass.UseSystemPasswordChar = true;
}
}
The best choice will be to implement your own small control that works as a half-transparent overlay with a spinning animation. Place it over the controls you want to hide and make it invisible by default. Then before you start your long async operation, you make it visible. On operation complete hide it again.
You can utilize ready controls like this for example http://www.codeproject.com/Articles/57984/WPF-Loading-Wait-Adorner