我有2個事件處理程序附加到同一表單上的按鈕。我想禁用窗體並在方法運行時顯示一個waitCursor,然後啓用窗體並將光標恢復爲默認值。相同形式的2個事件處理程序的行爲方式不同
以下是奇怪的部分:使用幾乎相同的代碼,其中一個事件起作用,另一個不起作用!這裏有什麼可能是錯的?
這一個工程。
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
}
- This works!你知道爲什麼嗎?你能解釋爲什麼嗎?我在這裏很神祕。 – MAW74656
「WIP」報告將焦點從您的應用程序中抽離出來。所以ActiveForm因爲null,沒有表單處於活動狀態。 –
好的,但爲什麼WIP做到這一點,並且Exception Report沒有? – MAW74656