The problem is that the button click event is happening almost immediately - so the second "click" is going to the correct place - the control at that position on the "new" panel. And that will generate a click event for the new button because that is exactly what should happen. If you want to stop it, then 1) Create a class level variable:
private DateTime lastSwap = DateTime.Now;
2) In the Button1 click handler, set it:
lastSwap = DateTime.Now;
And then swap panels. 3) In the Button2 click handler, check it and ignore if too soon:
if (DateTime.Now < lastSwap.AddMilliseconds(500)) return;
You can change the 500 to any value you think reasonable - 500 provides half a second.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
thanks for your quick response... code is working properly... but it is impossible to implement on big application where there are more then 20,25 panels and every control takes different time to execute.
You're missing the point. As a programmer, when you find a solution to the problem, but you have 25 problems - you dont implement the solution 25 times. You implement it once and re-use it 25 times.
Think of it this way - if you have 25 customers, you dont write 25 different classes to represent each customer, you implement once class called "Customer" and reuse it 25 times. The same thing applies here, you need a solution which stops a button being clicked within 500ms of another button (personally I think this is an awful solution to your original problem, but hey if it works for you go with it). Write a class which exhibits this behaviour and attach it to every button which requires it.
The 500ms had nothing to do with whatever task the button does, it had to do with stopping a quick double click operating a button which appears after the first click. It should not matter what the second button does!
Anyway your original question asked about 2 panels, and you got a solution to the question as stated. Ask the right question, and you'll get the right answer.