How to disable or throw away mouse events

  • Thread starter Thread starter Brian Richards
  • Start date Start date
B

Brian Richards

In my app I have some actions that take some time. So when a user clicks on
a button to perform said action in the event handler I set the cursor to
waitcursor and disable the button. What I was trying to accomplish was
preventing the user from inputing multiple events. What happens is the
messages just get queued up and the event handler fires off again. Is there
anyway for me to ignore those events all together? I'd like to be able to do
it at the control level but application wide may be acceptable.

The other method I tried was overriding the preprocessmessage function to
throw away all events if the forms busy flag is set like the following:

public override bool PreProcessMessage(ref System.Windows.Forms.Message msg)
{
if(!_busy)
{
return base.PreProcessMessage(ref msg);
}
else
{
//busy just return true
return true;
}
}

Any tips would be welcomed. Thanks.

-Brian
 
* "Brian Richards said:
In my app I have some actions that take some time. So when a user clicks on
a button to perform said action in the event handler I set the cursor to
waitcursor and disable the button. What I was trying to accomplish was
preventing the user from inputing multiple events. What happens is the
messages just get queued up and the event handler fires off again. Is there
anyway for me to ignore those events all together? I'd like to be able to do
it at the control level but application wide may be acceptable.

Mhm... Can you show some code? In general, the button should not
receive input events after being disabled.
 
If I click on the button twice it preforms the action twice:


private void button_Click(object sender, ClickEventArgs e)
{
_busy=true;
button.Enabled = false;
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
try
{
action();
}
catch (Exception ex)
{
//process exception
}
_busy=false;
button.Enabled = true;
this.Cursor = System.Windows.Forms.Cursors.Default;
}
 
If you just return when you are busy, does this handle the problem.

private void button_Click(object sender, ClickEventArgs e)
{
if(_busy)
return;
//continue with your present code.


===============
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Brian Richards said:
If I click on the button twice it preforms the action twice:


private void button_Click(object sender, ClickEventArgs e)
{
_busy=true;
button.Enabled = false;
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
try
{
action();
}
catch (Exception ex)
{
//process exception
}
_busy=false;
button.Enabled = true;
this.Cursor = System.Windows.Forms.Cursors.Default;
}
clicks
 
Back
Top