March 17, 2011

Builtin confirmation dialog in Windows Forms

var confirmResult =  MessageBox.Show("Are you sure to delete this item ??",
                                     "Confirm Delete!!",
                                     MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
    // If 'Yes', do something here.
}
else
{
    // If 'No', do something here.
}

TextBox Validation for Email address format

 private void txtMail_Leave(object sender, EventArgs e)
        {
            string s = "[a-z0-9A-z]@[a-zA-z0-9 ]*[.]";
            string s1 = txtMail.Text.ToString();
            Match aa = Regex.Match(s1, s);
            if (aa.Success)
            {
              
            }
            else
            {
                MessageBox.Show("E-mail Address is not in correct format");
                txtMail.Text = "";
                txtMail.Focus();
            }
        }