开发者

How to validate my windows forms in C#

开发者 https://www.devze.com 2022-12-14 21:04 出处:网络
How do开发者_运维技巧 I validate my windows forms in C#?Look into ErrorProvider Class. I am assuming here that you are trying to validateform controls.

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.

  1. How to: Display Error Icons for Form Validation with the Windows Forms ErrorProvider Component

  2. Extending Windows Forms with a Custom Validation Component Library

  3. Validating TextBox

  4. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消