Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling double click event of a button 3

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
Hello everyone I want to disable double click even of a button without disabling the button and without disabling the click event. In other words I want the user only to click on the button. Is it possible to do that? I have no idea. And how can I do that through VB.net 2005? Any help will be much appreciated.

Thank you so much in advanced
 
What does your button do when you double_click it, that you do not want to happen?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
It's a game and the button are checkers that shouldn't double clicked.
First of all, I was trying yesterday through a simple application with a button to appear a msgbox "clicked" and "double clicked" corresponding to the events. I ran it step over and I saw that double click event never fires. But only the click, I don't understand what's going on there. I would like to detect somehow wheather the click is double click, I don't know how to do that and to disable it. To prevent user double click it.
 
I know you think you answered my question, but you did not. You just re-stated what you want to do, but I still don’t know WHY?

"button are checkers that shouldn't double clicked" because...?

My point is: if you have code in Click event, but have nothing (no code) in Double_Click event (or you may not even have a double-click event), what difference it would make if your user double clicks on the button?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
There is no such thing as a double click event on a button (at least not in my version of VS), so this makes even less sense.
 
I have VS2010 and there is a double click event for buttons. The double click event never fires because the click event is fired. I just tried this on a form and it never entered the double click event. I don't know why there is a double click event available on buttons.

To answer the original question, though. Many events have the ability to cancel them by using e.Cancel = True. A button event does not have that as one of it's choices. So, I would say you can't cancel a button click event.

Tom
 
Here is a link that describes the button double click event. The page says the event is not raised by default.
From the page... "By default, the ControlStyles.StandardClick and ControlStyles.StandardDoubleClick style bits are set to false for the Button control, and the DoubleClick event is not raised."


I have never worked with ControlStyles and don't know how to change it.

Tom
 
VS 2010, VB.NET - mine has DoubleClick even for a Button:

Code:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) _
                          Handles Button1.Click
        Me.BackColor = Color.Red
    End Sub

    Private Sub Button1_[blue]DoubleClick[/blue](ByVal sender As Object, _
                                    ByVal e As System.EventArgs) _
                                Handles [blue]Button1.DoubleClick[/blue]
        Me.BackColor = Color.Blue
    End Sub
End Class

Click fires just fine - Form changes to Red, DoubleClick does not fire, even when entire Click event is erased.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
tcsbiz I already try it, as I mentioned above with no effect.
Andy this coce has no effect too.
The only event that fires is the click event its the same thing with tcsbiz's code.
I am using Vb.net 2005 as I mentioned above too.
The what happens when the user clicks on the button(checker) is that the checker play and it set to the appropriate position. Secondly depending on the game's rules sometimes the user has the possibility to play more than one time even with the same checker even with some other. BUT when I double click the checker it goes in unrelated positions without any reason.
As anyone of you saw the only event that fires even you click or double click on a button is the click event. So when I double click the checker by fault I want nothing to happen ;) That's what I am trying. If there isn't a way I will do all the job with drag and drop it and not by clicking it. But if it there is a way to do that it would save from writing code about drag and drop. Whatever. I don't understand too, how is it possible to exist the double click event and to be useless if you try to use it. I don't understan with that happens, I believe it should be seperated. I really don't understand. I don't know if I miss something in that.
 
According to what I read, depending on your settings a double click on the button will fires two click events. May be why it is moving, because it is executing the event twice. So I would try to set some form level variable that holds the time of the last click. If the time since the last click is not longer than some elapsed time do not handle the click event. If so then set the click time.
 
I didn't understand well what you mean!!!
I have an array of checkers, when the user plays he can move any checker he wants according to the dices. He can move the same checker for example for 1 to 4 times depending on the dices, he can move a checker 1 time and 3 times other checker.
When he moves 1 time the checker with the code executing in click event, it's ok, but if he double clicks on the checker we want to happen nothing. So I want something that recognizes the click and the double click event and the prevent to run of the click by default when double click is occured.
 
when I double click the checker it goes in unrelated positions without any reason.

Nothing happens for no reason in any program, you just didn't find your reason yet :)

Some of your code is executing when you double-click, or as MajP suggests: you (single) click twice, just very fast.

What happens when you click, and then click again? And then from the same position you double-click it?
Does your checker go to the same position in both cases?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Like I said there is no double click taking place. There are two single click events taking place. You can test this and prove it. So I do not think that you can stop the click event, but you could possibly undo/reset if a second click occurs shortly afterwards. I would think the only thing to do is to check to see the duration between clicks. If that duration is less than some time interval, then "undo" the move making it appear as nothing happened.
 
I took a look here and it says that in reallity button1 has no double click even if I can write it to code!!!!!

Andy you are right, I found that the double click was on the board by momentum and limitely with the checker so that I couldn't see which code was executing exactly. Fortunately board is a picture box and it has double click event, so I corrected it by setting a flag when it's double clicked and it's ok now. All that caused the unrelated set of the checker. Excuse me for that!!! However I still don't understand how buttons don't have double click because anyone might need to have other code in click and other code in double click event.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top