У меня возникла проблема с проверкой компонентов texbox в проекте winforms C#.Остановить событие проверки при запуске, при смене фокуса текстового поля
У меня есть несколько текстовых полей в форме «Создать продукт», которая проверяет числа, пустой поток и т. Д. Если я перехожу из одного текстового поля (с проверкой) в другое, происходит событие проверки, и я не могу изменить фокус, т. Е. Застрять в текстовом поле, пока не наберу что-то. Поведение, которое я искал, должно запускать события проверки в текстовых окнах, когда я нажимаю кнопку «Создать», а не когда меняю фокус с одного текстового поля на другое.
Любые подсказки или правильная практика как решить эту проблему? Высоко ценится ..
Текущий код:
//Validation event for one of the textboxes. epProductName is an ErrorProvider:
private void txtProductName_Validating(object sender, CancelEventArgs e)
{
if (Validator.IsEmpty(txtProductName))
{
epProductName.SetError(txtProductName, "Field must not be empty");
e.Cancel = true;
}
else
{
epProductName.Clear();
}
}
//Submit button click event
private void btnSubmit_Click(object sender, EventArgs e)
{
if (ValidateChildren())
{
try
{
SelectedProduct.ImagePath = txtChoosePicture.Text;
SelectedProduct.InstructionPath = txtChooseManual.Text;
SelectedProduct.SheetPath = txtChooseDatasheet.Text;
SelectedProduct.IsDeleted = false;
SelectedProduct.ProductNameNum = txtProductName.Text;
SelectedProduct.Description = txtProductDescription.Text;
SelectedProduct.DaysToExpire = int.Parse(txtUseTime.Text);
SelectedProduct.Category_Id = (int)cbChooseCategory.SelectedValue;
int productId = pm.CreateProduct(SelectedProduct);
MessageBox.Show("New Product: Id: " + productId + ", Product name: " + SelectedProduct.ProductNameNum, "New product created",
MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
this.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("Product was not created. Details: " + ex.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
}