I am on a project and this project needs to take randomly 16 bytes from random.org. I can take it from website and write this 16 bytes to a textedit. I also have a refresh button. Everytime this button is clicked, new 16 byte comes and it is written in textedit.
I want to prevent the user to click refresh button sequentially. What I want is to disable refresh button after it is click. However, another thing I want is to enable this button after 30 seconds automatically.
I've tried thread.sleep(30000)
in the button click event but it stops whole program for 30 seconds. I want to disable just refresh button for 30 seconds, not the rest of the program.
I am thinking to show to the users kind of stopwatch so that they can see how much time they should wait for next click. For example, after they click refresh button, there appears this 30 seconds stopwatch.
If we are talking about WPF here, there is a way to achieve the desired behavior with EventTriggers without any code-behind:
<Style TargetType="Button">
<Style.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False" />
<DiscreteBooleanKeyFrame KeyTime="00:00:30" Value="True" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With