First of the counter variable:
1) you can declare as a field variable
2) you can make it as a static variable inside the button's click event.
secondly and lastly, you're trying make the panel2 visible whenever your limit is 3 or 5. You don't have to tell the computer to make panel2 visible...