b_levitt
asked on
WaitCursor Between forms often doesn't show up
I try to set Cursor.Current=Cursors.Wai tCursor, when ever I have a long running operation. However, I'm noticing, that sometimes it doesn't work or there is a significant delay. The biggest culprit is when I set it before loading and showing a modal form, ie...
Cursor.Current = Cursors.WaitCursor;
Form formToLoad = null;
switch (formNumber)
{
case "1":
formToLoad = new App1MainMenu();
break;
case "2":
formToLoad = new App2.FDEMainMenu();
break;
}
if (formToLoad != null)
formToLoad.ShowDialog();
If I break in the debugger prior to the showdialog line, it works fine. Some ShowDialog trickery in my baseclass also works:
private void BaseForm_Activated(object sender, EventArgs e)
{
Timer cursorTimer = new Timer();
cursorTimer.Tick += new EventHandler(cursorTimer_T ick);
cursorTimer.Interval = 500;
cursorTimer.Enabled = true;
}
void cursorTimer_Tick(object sender, EventArgs e)
{
Cursor.Current = Cursors.Default;
((Timer)sender).Enabled = false;
}
new public DialogResult ShowDialog()
{
Cursor.Current = Cursors.WaitCursor;
return base.ShowDialog();
}
Is there a better way to do this?
Cursor.Current = Cursors.WaitCursor;
Form formToLoad = null;
switch (formNumber)
{
case "1":
formToLoad = new App1MainMenu();
break;
case "2":
formToLoad = new App2.FDEMainMenu();
break;
}
if (formToLoad != null)
formToLoad.ShowDialog();
If I break in the debugger prior to the showdialog line, it works fine. Some ShowDialog trickery in my baseclass also works:
private void BaseForm_Activated(object sender, EventArgs e)
{
Timer cursorTimer = new Timer();
cursorTimer.Tick += new EventHandler(cursorTimer_T
cursorTimer.Interval = 500;
cursorTimer.Enabled = true;
}
void cursorTimer_Tick(object sender, EventArgs e)
{
Cursor.Current = Cursors.Default;
((Timer)sender).Enabled = false;
}
new public DialogResult ShowDialog()
{
Cursor.Current = Cursors.WaitCursor;
return base.ShowDialog();
}
Is there a better way to do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also, Cursor.Show() may work, right after you change the cursor.
ASKER
I appologize for the delay. While I've not had a chance to test this fully, DoEvents did seem to work. Cursor.Show did not.