Windows Develop Bookmark and Share   
 index > Windows Forms General > How to block events in a form
 

How to block events in a form

I've got the following problem. I need to block any event in a form while a separate thread is working.

I've tried to use

form.Cursor = Cursors.WaitCursor;

but it doesn't work since I can close the form. Of course there's a way to make the form disabled but it's not good solution for me. Any other suggestions?

bulklodd  Friday, January 20, 2006 8:24 AM

Do you mean, you don't want the user to click on any button on the form? cause if so, the disabled is a good option, antoher option is to hold a flag (acceptEvent) on the form, and on the thread start, set it to false, and on the events handler use:

public void button_Click(object sender, EventArgs)

{

if(acceptEvent)

{

// handle the event.

}

}

Eli Gazit  Friday, January 20, 2006 8:34 AM

Thanks for your response. I've already had flag but I don't like it cos it makescode more complex. I hoped to get something like this:

Application.AcceptEvents = false;

....

Application.AcceptEvents = true;

it looks simpler and I don't need to provide each event handler with a special code.

bulklodd  Friday, January 20, 2006 8:58 AM
What you call AcceptEvents is the Enabled property. That's how you prevent a Form from being accessible. Why doesnt that work for you? And if you dont want the form to handle events, why are you doing your other work in a separate thread?
CommonGenius.com  Friday, January 20, 2006 2:22 PM

You can do something similar to this using the IMessageFilter interface.

You can look at an example I've posted on my blog at http://saguiitay.wordpress.com/2006/01/19/filtering-win32-messages-of-a-form/

The idea is just to pre-process all the messages before they arrive to the form.

Itay Sagui  Saturday, January 21, 2006 1:17 AM

You can use google to search for other answers

Custom Search

More Threads

• How can I add same project in two different solution pointing to the same project in VSS
• save and display images
• How to change the button name in a Folder Browser Dialogs in C#
• Document_Completed is showing more then once on one WWW. How to determine page is loaded?
• That cool buttonin Windows media player 11
• Can ExtractAssociatedIcon use a network path?
• How to get checkboxes in ComboBox
• How do you replace a new line in a string from an RTF control?
• Right to left
• InterpolationMode.HighQualityBicubic: Unwanted borders added to resampled graphic