У меня есть 2 обработчика событий, прикрепленных к кнопкам в одной форме.Я хочу отключить форму и показать waitCursor во время работы метода, затем включить форму и вернуть курсор к значению по умолчанию.
Вот странная часть: при почти одинаковом коде одно из этих событий работаета другой нет!Что может быть здесь не так?
Это работает.
private void btnExceptionReport_Click(object sender, EventArgs e)
{
lblStatus.Text = "Printing exception report.";
ActiveForm.Cursor = Cursors.WaitCursor;
//Form.ActiveForm.Enabled = false;
if (DatabaseOps.printItemReport("Exceptions", cboEmployee.Text))
{
lblStatus.Text = "Exception report printed.";
}
else
{
MessageBox.Show("Error printing exception report.");
lblStatus.Text = "Error printing Exception report.";
}
//Form.ActiveForm.Enabled = true;
ActiveForm.Cursor = Cursors.Default;
}
В то время как этот выдает ошибку, когда я пытаюсь вернуть курсор на значение по умолчанию, утверждая, что ActiveForm
равно null
.
private void btnWIPReport_Click(object sender, EventArgs e)
{
lblStatus.Text = "Printing WIP Materials report.";
ActiveForm.Cursor = Cursors.WaitCursor;
//Form1.ActiveForm.Enabled = false;
if (DatabaseOps.printItemReport("WIP", cboEmployee.Text))
{
lblStatus.Text = "WIP Materials report printed.";
}
else
{
MessageBox.Show("Error printing WIP Materials report.");
lblStatus.Text = "Error printing WIP Materials report.";
}
//Form1.ActiveForm.Enabled = true;
ActiveForm.Cursor = Cursors.Default; //This line gives error saying ActiveForm is null
}