This code shows how we can use error provider on our windows form application using c#.
public partial class frmLogin_errorProvider : Form
{
public frmLogin_errorProvider()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
errorProvider1.Clear();
if (string.IsNullOrEmpty(txtPassword.Text))
{
errorProvider1.SetError(txtPassword, "Password is required.");
txtPassword.Focus();
}
if (string.IsNullOrEmpty(txtUsername.Text))
{
errorProvider1.SetError(txtUsername, "Username is required.");
txtUsername.Focus();
}
// Our code processing starts here.
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
No comments:
Post a Comment