Link to home
Start Free TrialLog in
Avatar of cjinsocal581
cjinsocal581Flag for United States of America

asked on

Button press configuration in VB.NET

Here is something custom I am trying to do. Please let me know if it is even possible to do this.

When I press a button, it should operate normally.

But, when I press and hold the button for 2 seconds, pop a context menu with an option named "Reset"

Ideas?
Avatar of GlassCubeMedia
GlassCubeMedia

You could use the mouse down event and then run a thread that sleeps for 2 seconds before calling a function. Then in the mouse up have a function that cancels the thread.

I'm not near VS.NET but here is how i think it should work.

Imports System.Threading

Private timerThread As Thread
Private cancelThread As Boolean = False

Private Sub DelayedPopup()
   Thread.Sleep(2000)
   If cancelThread = False Then
      ContextMenu.Show()
   End If
End Sub

Private Sub Button1_MouseDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseDown
   timerThread = New Thread(New ThreadStart(AddressOf DelayedPopup))
   timerThread.Start
   cancelThread = False
End Sub

Private Sub Button1_MouseUp(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseUp
   timerThead = Nothing
   cancelThread = True
End Sub


That should do it. Not sure if it works because right now I'm on linux. But that concept will work

Hope That Helps

Matt
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cjinsocal581

ASKER

Second solution worked the way I needed. Thanks for the effort to both.