
Signature
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us>> wrote:
> > Can anyone tell, how to resolve this situation? I require that the user
> > clicks should be ignored when the button is disabled.
>
> Why dont you just use a WaitCursor ? in this way your form cannot receive
> any click.
Yes it can. Try this:
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
public class Test
{
static int count;
[STAThread]
static void Main()
{
Form f = new Form();
f.Size = new Size (200, 200);
f.Location = new Point (100, 100);
Button b = new Button();
b.Size = new Size (190, 190);
b.Location = new Point (0, 10);
b.Text = "Click me";
b.Click += new EventHandler(ClickHandler);
f.Controls.Add(b);
Application.Run (f);
}
static void ClickHandler(object sender, EventArgs e)
{
Control c = (Control) sender;
count++;
c.Text = count.ToString();
Cursor.Current = Cursors.WaitCursor;
Thread.Sleep (2000);
}
}
Start this up, and then click rapidly times on the button, several
times. You'll see the event getting fired multiple times, even though
most of the clicks are performed when the cursor is a wait cursor.
> Also, consider a more userfriendly interface, like using a thread to load
> the data this will prevent the locking of the UI
That's the right answer :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Ignacio Machin ( .NET/ C# MVP ) - 30 Dec 2005 19:01 GMT
Hi,
> Start this up, and then click rapidly times on the button, several
> times. You'll see the event getting fired multiple times, even though
> most of the clicks are performed when the cursor is a wait cursor.
Interesting, I had never tried that
I was about to post it when I though that the above problem will happens no
matter what. if you are quick enough you can send a couple of events to the
queue before the handler is even invoked.
>> Also, consider a more userfriendly interface, like using a thread to load
>> the data this will prevent the locking of the UI
>
> That's the right answer :)
More like part of it, still the UI needs to reflect the fact that an action
is being performed in the background at least to disable/enable the controls
accordingly.

Signature
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jon Skeet [C# MVP] - 30 Dec 2005 19:58 GMT
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us>> wrote:
> > Start this up, and then click rapidly times on the button, several
> > times. You'll see the event getting fired multiple times, even though
[quoted text clipped - 5 lines]
> matter what. if you are quick enough you can send a couple of events to the
> queue before the handler is even invoked.
Yes, that's true. Possibly the easiest way to solve that problem is to
check whether the "sender" of the event is enabled, and to ignore it if
it's not. I *think* that would work...
> >> Also, consider a more userfriendly interface, like using a thread to load
> >> the data this will prevent the locking of the UI
[quoted text clipped - 4 lines]
> is being performed in the background at least to disable/enable the controls
> accordingly.
Oh certainly.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Ignacio Machin ( .NET/ C# MVP ) - 30 Dec 2005 19:06 GMT
Hey Jon,
If you are in UK it should be night already , why aren;t you drinking a
pint?
It's just 2PM here and I have one more hour to leave :(
Jon Skeet [C# MVP] - 30 Dec 2005 20:00 GMT
<"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
dot.state.fl.us>> wrote:
> If you are in UK it should be night already , why aren;t you drinking a
> pint?
I'm still on Christmas holiday - back to work on Tuesday.
> It's just 2PM here and I have one more hour to leave :(
LOL. These days I post more from home than from work anyway - hence my
rather higher number of posts this month than normal. (I don't know
what Nick's excuse is :)

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nicholas Paldino [.NET/C# MVP] - 31 Dec 2005 16:55 GMT
Don't let Jon tell you that he doesn't go out for a pint. I know first
hand that he can handle it.
As for my excuse, I like to let the computer screen warm me on those
cold, lonely nights. =)

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> <"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT
> dot.state.fl.us>> wrote:
[quoted text clipped - 8 lines]
> rather higher number of posts this month than normal. (I don't know
> what Nick's excuse is :)