المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : button onclick event



C# Programming
07-28-2009, 11:10 PM
To whom it may concern,

I have a button onclick event, where I disable the button (setting its enable property to false), have some process which takes some time, and then reenabling the button at the end of the onclick event function. My query is that the onclick event is fired even though the button has been disabled (clicking more than once while the button is still disabled).

The following snippet illustrates the problem. Any solutions are appreciated.

private void button1_Click(object sender, EventArgs e)
{
DateTime d1, d2;
TimeSpan t;
d1 = DateTime.Now;

if (button1.Enabled == false)
return;

button1.Enabled = false;
while (true)
{
d2 = DateTime.Now;
t = d2.Subtract(d1);
if (t.TotalMilliseconds > 2000)
break;
}

label1.Text = (count++).ToString(); // shows the number of times the function has been called (count is a global variable)
label1.*******();

button1.Enabled = true;
}

Thanks in advance