Preventing user interaction while showing a "wait" cursor

A

Aaron Queenan

I have a form which performs some asynchronous code. I want to display a
wait cursor when it starts, and hide the wait cursor when it has completed.
This part works fairly well, using:

this.TopLevelControl.Cursor = System.Windows.Forms.Cursors.WaitCursor;

I also want to prevent user interaction with the controls on my form while
the wait cursor is displayed, so that use events (except resize and cancel)
are blocked. What is the recommended way of doing this in .NET?

Thanks,
Aaron Queenan.
 
J

Jan Tielens

You can set the Enabled property of a control or even a form to false. This
will prevent any user interaction.
 
H

Herfried K. Wagner [MVP]

* "Aaron Queenan said:
I have a form which performs some asynchronous code. I want to display a
wait cursor when it starts, and hide the wait cursor when it has completed.
This part works fairly well, using:

this.TopLevelControl.Cursor = System.Windows.Forms.Cursors.WaitCursor;

I also want to prevent user interaction with the controls on my form while
the wait cursor is displayed, so that use events (except resize and cancel)
are blocked. What is the recommended way of doing this in .NET?

Disable the controls...
 
A

Aaron Queenan

Unfortunately, it will also change the background colour to grey, does some
wierd colouring of ListView controls which have items in, and inconsistently
disables scrollbars depending upon where they are and who owns them. :-(

Is there any way I can disable the user interaction _without_ setting the
Enabled property to false?

Thanks,
Aaron.
 
N

Nicholas Paldino [.NET/C# MVP]

Aaron,

You could override WndProc, and just toss out most of the messages that
come into the window. Of course, you would have a property that would turn
on and shut off this behavior. You will probably want to still handle
WM_PAINT messages, at the least.

Hope this helps.
 
G

Guest

this.Enabled = false,

Everytime I do a modal dialog box I do this because its highlighting the
modal box thats centered on the parent. Less visual clutter.


Justin Rogers said:
Easier than disabling the controls is displaying a dialog over top of the
form...

http://weblogs.asp.net/justin_rogers/archive/2004/01/22/61564.aspx

The above code demonstrates the display of a transparent *gamma* form that makes
the controls darker and intercepts any mouse/keyboard input while the form is
*busy* or in the case I posted *sleeping*.
 
H

Herfried K. Wagner [MVP]

* "Justin Rogers said:
Easier than disabling the controls is displaying a dialog over top of the
form...

http://weblogs.asp.net/justin_rogers/archive/2004/01/22/61564.aspx

The above code demonstrates the display of a transparent *gamma* form that makes
the controls darker and intercepts any mouse/keyboard input while the form is
*busy* or in the case I posted *sleeping*.

This will work too, but notive that transparency isn't supported by all
Windows versions.
 
H

Herfried K. Wagner [MVP]

* said:
Better idea this.Hide(). Why let them see what they cant touch?

Mhm... What would you say if an application suddenly is invisible?!
 
G

Guest

Its not visible, its got another modal form displayed. The lower form is no
longer needed,
 
A

Aaron Queenan

Thankyou Justin.

I had been toying with the idea of an extra dialogue box, but your
suggestion goes that litte bit further and looks like a great way of
handling the problem. :)

Justin Rogers said:
Easier than disabling the controls is displaying a dialog over top of the
form...

http://weblogs.asp.net/justin_rogers/archive/2004/01/22/61564.aspx

The above code demonstrates the display of a transparent *gamma* form that makes
the controls darker and intercepts any mouse/keyboard input while the form is
*busy* or in the case I posted *sleeping*.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top