How would I check if certain fields are incomplete?
I wan开发者_如何学JAVAt it so that whenever somebody clicks my button called "ADD?" that a messagebox will appear if required fields have not been properly filled out.
In your event handler for the "Add" button, just check to see if the "field" has been filled in, and if not, don't continue:
void buttonAdd_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(textBoxField.Text))
{
// Show message?
MessageBox.Show(....);
return; // Don't process
}
// Field has a value, do your thing here...
}
Use a errorprovider component, or simply check the input text length if it is 0 throw up a message
If (myTextBox.Text.Length == 0)
{
//throw up message box
MessageBox.Show("You forgot to fill in this field!");
return;
}
精彩评论