Click event on buttons with the same location on different Forms

  • Thread starter Thread starter Mihai Tataran
  • Start date Start date
M

Mihai Tataran

Hello,
I have a strange problem regarding the handling of the Click events in a
Windows CE (with .NET Compact Framework) application.

Here it is:
1. I am in FormA and i press a button which would make the application
navigate to a FormB. But i accidentally press it twice.
2. The unloading of FormA and loading of FormB takes a few seconds because
of many controls which both have.
3. The second click is handled by a button on FormB with the same location
as the initial button on FormA. The most interesting part is that the button
on FormB is disabled.

I don't want the application to react on the second click, since it is made
accidentally - and more sadly it is handled by a button on FormB.

I have also made some tests on a Windows XP with .NET Framework. I have the
same problem here.

Here is some sample code:

//
// button1 on FormB (in InitialiseComponent method)
//
this.button1.Enabled = false;

// ....

private void Form2_Load(object sender, System.EventArgs e)
{
Application.DoEvents();
this.button1.Click +=new EventHandler(button1_Click);
this.button1.Enabled = true;
}

Could you please help?

Thanks,
Mihai
 
I must admit I have never found this to be a problem. If the form does take
a while to load try spliting the controls up into tabs then loading controls
as and when required.
Or in extreme cases, multithreading.

But..you could try this in the button1_Click event handler:

if (Visible)
{
//do my stuff
}

Regards
Simon.
 
Hello again,

I have tried some different things last evening, and it seems i have found
the solution: call Application.DoEvents() after the InitializeComponent() of
each form.

Mihai
 
Back
Top