Question:
visual basic: how to make a button click able only once?
?
2010-08-06 14:59:25 UTC
I made a program. but i want people who uses the program to click the button once they cant click the same 1 again so how can i make them click it once then disable the button???
i using visual basic
Six answers:
Gary B
2010-08-06 15:29:02 UTC
Setting the button's Enabled property to False should do the trick. The problem you'll run into is that the button still has the focus after it's clicked, which happens to be right when you're trying to disable it. You can't disable a control that's holding focus.



Hopefully, you'll have some other control on the form that you can give focus to first. If the magic button is named Button and there is also a text box named TextBox, you could try



TextBox.SetFocus

Button.Enabled = False



somewhere in your Button_Click() event.





Additional Response:

If you need to track the number of clicks, then declare a variable for that purpose and use it.



It seems that your question has changed. At first, it sounded like you were asking what methods or properties of command buttons are used for disabling the control. Now it sounds like you're asking how to program a task that you don't know how to clearly describe.



What is the task? Do you have one button that should be disabled the first time it's clicked? Do you have several buttons that can be clicked in any order, as long as the same button isn't clicked twice in a row? Do you need to execute a different routine the first time a button is clicked than any other time that button is clicked?



This is just programming. You can call any number of routines in a single event. You can call them conditionally. You can track states, whether exposed by another object or defined in your own code. But, first, you have to be able to explain what you want to do, if not to us then at least to yourself, in enough detail to make coding possible.



What, really, is the behavior you want to code?
Robin
2016-04-13 13:35:37 UTC
You can use the enable property of the button to disable it once its clicked howevere this is not the best method because it caused the button to look greyed out. A better method which will preserve the look during the game is to use an IF statement which checks for an empty button text property. If there is an x or o the if will bypass that code which places an x or o. Just wrap the section of code you are using now with an if statement
anonymous
2010-08-06 21:54:00 UTC
Private Sub Button1_Click



Button1.Visible = False

End Sub



It's pretty easy!
anonymous
2010-08-06 15:04:29 UTC
in the click event:





command1.enabled = false



End Sub



That should Grey it out afterward, depending on what version of Visual Basic you're using. Alternatively, you could do command1.visible = false



Also, replace command1 with whatever you named your button.
Kathy
2017-02-28 01:47:48 UTC
1
anonymous
2016-06-04 01:15:08 UTC
The writing jobs aren’t difficult, so anyone who has good writing expertise will be ready to excel so if you will like to give it a shoot at earning money effortlessly and exciting you need to try a site


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...