question about windows forms checkbox
private void frmSearch_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bookdatabaseDataSet.Dist_Year' table. You can move, or remove it, as needed.
this.dist_YearTableAdapter.Fill(this.bookdatabaseDataSet.Dist_Yea开发者_如何学编程r);
// TODO: This line of code loads data into the 'bookdatabaseDataSet.Dist_Auth' table. You can move, or remove it, as needed.
this.dist_AuthTableAdapter.Fill(this.bookdatabaseDataSet.Dist_Auth);
// TODO: This line of code loads data into the 'bookdatabaseDataSet.Book' table. You can move, or remove it, as needed.
this.bookTableAdapter.Fill(this.bookdatabaseDataSet.Book);
}
private void button1_Click(object sender, EventArgs e)
{
Form f4 = new Confirm();
f4.Show();
Hide();
}
private void button2_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to Exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Application.Exit();
}
}
my question is: I want from the form to give me error message if I didn't check any of the check boxes. what is the correct code for it? and where should I right it? and thanks a lot for your concern. form of windows application
For every checkbox do a checkbox.Checked test (boolean AND) and display a message box.
If you wanted to prevent the closing of the application then you have to handle the closing event and set CANCEL to true in this case.
void HandleFormClosing (object sender, CancelEventArgs args)
{
if (checkbox1.Checked && checkbox2.Checked)
return;
MessageBox.Show ("Need to check all boxes");
args.Cancel = true;
}
I guess you want to ensure at least one checkbox is checked when button1
is clicked, right? If so, place it at the beginning of button1_Click
event.
private void button1_Click(object sender, EventArgs e)
{
if (!checkbox1.Checked && !checkbox2.Checked && !checkbox100.Checked)
{
MessageBox.Show("Please select a checkbox.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
checkbox1.Focus();
}
else
{
Form f4 = new Confirm();
f4.Show();
Hide();
}
}
This will not give you a direct answer (work-done-just-for-you kind of answer), but should point you in the right direction:
Finding the selected Radiobutton's value in ASP.NET
You can do this using custom validation.
But you could also get rid of the checkboxes and assume that if the user types in the textbox then they want to do a search on the field.
Start with search button disabled and only enable it when at least one field has text in it.
精彩评论