Thursday, April 23, 2020

How to use ErrorProvider using C#



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

How to use combobox using c#

This code shows how we can use combobox in our winforms application using c#.     public partial class frmComboBox_Demo : Form     {...