Click here to Skip to main content
15,942,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. What I want is to limit users to click maximum 5 clicks and if they re-click, can not get what I give and they should wait for 1 day. Could you help me because I do not know how to code it? Thanks a lot!


EDIT: Windows Form.

What I have tried:

Nothing. I do not know how to code it.
Updated 30-Dec-18 2:22am
Richard MacCutchan 30-Dec-18 7:40am    
It all depends on where they click.
Member 14065947 30-Dec-18 7:44am    
I mean they click to a button and to the button should limit it 5 uses for each guy
Richard MacCutchan 30-Dec-18 8:38am    
So every time they click the button add 1 to a counter. When the counter reaches 5 set the Enabled property to false.

1 solution

You need to keep a record of clicks: that isn't difficult, just use a List of DateTime objects.
When they click the button, get the current timestamp (DateTime.Now will do it) and use AddDays(-1) to set it back to the beginning of your check period. Now look back through the List and find how many items are still greater than the end time. If it's five or more, refuse to allow the operation.
If it isn't, add the timestamp to the List, and allow the operation.

If you need this to work even if they exit your app, then you need to save and load the List when you exit and start.
Share this answer
Member 14065947 30-Dec-18 8:33am    
Thanks I will give it a try!
OriginalGriff 30-Dec-18 8:45am    
You're welcome!
Member 14065947 30-Dec-18 19:21pm    
@OriginalGriff I tried it but it's giving me errors. Can you please write the code because I think do somewhere mistake?
OriginalGriff 31-Dec-18 2:55am    
No, writing the code is what you get paid for! :laugh:
What errors do you get?
Member 14065947 31-Dec-18 3:57am    
Sorry. I mean will get errors because I do not know how to code it my mistake. Could you please help me out? Also the program I make it's free no paid that's why I want to add limit to users:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900