- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace ManagementApplication
- {
- public partial class UserRegistration : Form
- {
- // public String characters = "abcdeCDEfghijkzMABFHIJKLNOlmnopqrPQRSTstuvwxyUVWXYZ";
- public UserRegistration()
- {
- InitializeComponent();
- }
- private void UserRegistration_Load(object sender, EventArgs e)
- {
- WindowState = FormWindowState.Maximized;
- dateTimePicker1.Format = DateTimePickerFormat.Short;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- TextBox[] text = new TextBox[5];
- text[0] = textBox1;
- text[1] = textBox2;
- text[2] = textBox3;
- text[3] = textBox4;
- text[4] = textBox5;
- foreach ( TextBox txt in text )
- {
- if (txt.Text == "")
- {
- MessageBox.Show("Field Can't be Blank");
- break;
- }
- }
- if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "")
- {
- for (int i = 0; i <= 4; i = i + 1)
- {
- text[i].Text = "";
- }
- MessageBox.Show("Your data has been added your data successfully");
- }
- }
- }
- }
In this tutorial we will learn how to validate all textbox controls of the window application. The code is given please use it
