c# determine that all textbox component text is not empty

 foreach (Control c in this.Controls)
            {
                if (c is TextBox)
                {
                    if (string.IsNullOrEmpty((c as TextBox).Text))
                    {
                        MessageBox.Show("文本框不能为空");
                        break;
                    }
                    else
                    {
                        MessageBox.Show("添加成功");
                        this.Close();
                    }

Process: traverse all components to
determine whether it is a textbox to
determine whether the text of the textBox is empty. If
yes, it will pop up "Text box cannot be empty",
otherwise it will pop up "Add successfully"

ps: directly put the code in the button event to run
Example:

   private void button1_Click(object sender, EventArgs e)
    {
        foreach (Control c in this.Controls)
        {
            if (c is TextBox)
            {
                if (string.IsNullOrEmpty((c as TextBox).Text))
                {
                    MessageBox.Show("no");
                    break;
                }
                else
                {
                    MessageBox.Show("添加成功");
                    this.Close();
                }
            }
        }
    }

Guess you like

Origin blog.csdn.net/ssdssa/article/details/109007835