You could use an integer variable for this (a form class member), say
int current_state = 0;
Then:
- in
button1
click event handler set current_state=1
. button4
click event handler sets current_state=2
only if current_state==1
, otherwise it sets current_state=0
.button2
click event handler calls button5.show()
only if current_state==2
(and sets anyway current_state=0
).