private bool ValidateTextboxes() { bool isValidated = true; foreach (Control control in this.Controls) { if (control is MetroTextBox) { MetroTextBox textbox = control as MetroTextBox; if (control.Text == string.Empty) { textbox.WithError = true; textbox.BackColor = Color.FromArgb(255, 235, 238); isValidated = false; ErrorTracker.SetError(textbox, this.errorProvider); } else { textbox.BackColor = Color.White; textbox.WithError = false; ErrorTracker.RemoveError(textbox); } } } ErrorTracker.DisplayError("This field cannot be empty."); return(isValidated); }