Professional Documents
Culture Documents
CUSC | Ng Tng Dn
/// <summary> /// Check all text box must be input /// </summary> /// <returns>true if all input</returns> private bool ControlCheck() { if (txtName.Text == "") { MessageBox.Show("Name not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); return false; } if (txtAge.Text == "") { MessageBox.Show("Age not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); return false; } if (txtAddress.Text == "") { MessageBox.Show("Address not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAddress.Focus(); return false; } if (txtCity.Text == "") { MessageBox.Show("City not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCity.Focus(); return false; } if (txtCountry.Text == "") { MessageBox.Show("Country not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCountry.Focus(); return false; } if (txtYoE.Text == "") { MessageBox.Show("Years of experience not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtYoE.Focus(); return false; }
CUSC | Ng Tng Dn
if (txtQuantification.Text == "") { MessageBox.Show("Quantification not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtQuantification.Focus(); return false; } if (txtPhone.Text == "( ) -") { MessageBox.Show("Quantification not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtPhone.Focus(); return false; } if (txtEmail.Text == "") { MessageBox.Show("Email not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtEmail.Focus(); return false; } if (txtDate.Text == " / /") { MessageBox.Show("Date not null", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); txtDate.Focus(); return false; } return true; }
3. Text box age only accept digit character: Using keypress event
/// <summary> /// only accept number /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void txtAge_KeyPress(object sender, KeyPressEventArgs e) { if (Char.IsLetter(e.KeyChar)) { MessageBox.Show("Accept only number!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); e.Handled = true; } if (!(Char.IsDigit(e.KeyChar) || Char.IsControl(e.KeyChar))) { e.Handled = true; } }
CUSC | Ng Tng Dn
5. Now we get value and display by message box a. Check valid all information bay call ControlCheck() method. b. Get value. c. Display Using Click event of submit button
private void btnSubmit_Click(object sender, EventArgs e) { if (!ControlCheck()) return; string infor = "Information of applican: \n"; infor += txtName.Text + "\n"; infor += txtAge.Text + "\n"; infor += txtAddress.Text + "\n"; infor += txtCity.Text + "\n"; infor += txtState.Text + "\n";
CUSC | Ng Tng Dn
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure close this form ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { e.Cancel = true;
CUSC | Ng Tng Dn
b. Set order
CUSC | Ng Tng Dn
CUSC | Ng Tng Dn