How to validate my windows forms in C#
How do开发者_运维技巧 I validate my windows forms in C#?
Look into ErrorProvider Class. I am assuming here that you are trying to validate form controls.
How to: Display Error Icons for Form Validation with the Windows Forms ErrorProvider Component
Extending Windows Forms with a Custom Validation Component Library
Validating TextBox
Link
If you're looking for simple text value or checkbox checking, such as in a login form or acceptance of terms of services, you can use something like:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "check text" &&
textBox2.Text == "check another field" &&
checkBox1.Checked)
{
//perform actions
}
else
{
MessageBox.Show("Your input failed validation.");
}
}
Where button1 is the submit button, and textBox1, textBox2, and checkBox1 are various fields that are being validated.
精彩评论