Mousedown event on winform button on touch screen - vb.net

I have a vb.net winform application with a button that starts some motors (but that could be anything) on the mouse down event.
Private Async Sub btnForward_MouseDown(sender As Object, e As MouseEventArgs) Handles btnForward.MouseDown
Await _brick.DirectCommand.TurnMotorAtPowerForTimeAsync(OutputPort.B + OutputPort.C, 100, 30000, False)
End Sub
Private Async Sub btnForward_MouseUp(sender As Object, e As MouseEventArgs) Handles btnForward.MouseUp
Await _brick.DirectCommand.StopMotorAsync(OutputPort.All, False)
End Sub
This works fine on my desktop PC where I am using a mouse. But this does not work on a touch screen device. Although the touching of the screen is interpreted a s a mouse click event, the mouse down event does not trigger and a prolonged touch is then interpreted as a right click. Is there a work around for this? So far all I found where suggestions to move the finger to trigger the mouse down event.
Thanks!

Related

Mousemove detect left click not firing in usercontrol winform

I know this should be simple to do but for some reason I can't get a simple mousemove when I left click the mouse. this inside a custom button I have made with 2 labels in it. I am moving only on the button area and not the label. When I move over the button I see "Mousemove" printed to the console but when I hold the left click I get nothing...Not even the "Mousemove". I looking to implement a dragdrop for this button and was just starting out simple to detect the left click and mousemove. Am I missing another setting. I had a Click event and event removed that just to detect this movement.
Thanks in advance for any info.
Public Sub New()
'InitializeComponent()
DoubleBuffered = True
AllowDrop = True
End Sub
Private Sub CustomerButton_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Debug.Print("MouseMove")
If e.Button = MouseButtons.Left Then
Debug.Print("MouseMove and Left Click")
End If
End Sub

Use mouse scroll anywhere on screen in VB.net

I'm trying to setup global shortcut using mouse button and scrolling combination, (scrolling up (or down) whlie pressing right mouse button).
I'm thinking I should try to react to mouse scroll, but I have no idea how to detect mouse wheel outside of form.
Right now I got it to react to mouse click with timer and setting form to always on top (no prolem with it being always on top), but no idea how to progress with it.
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If MouseButtons.HasFlag(MouseButtons.Right) = True Then
TextBox1.Text = "YES"
Else
TextBox1.Text = "NO"
End If
End Sub
Goal is to make it minimize aplications set by user with that shortcut, just in case that info is helpful. I have rest of the code just cant figure that part out.
EDIT:
It works inside form with this:
Private Sub ListBoxCHOWAJ_MouseWheel(sender As Object, e As MouseEventArgs) Handles ListBoxCHOWAJ.MouseWheel
If MouseButtons.HasFlag(MouseButtons.Right) = True Then
If e.Delta > 0 Then
TextBox1.Text = "up"
Else
TextBox1.Text = "down"
End If
End If
End Sub
You need a mouse hook to detect scrolling outside your application. Have a look at my InputHelper library and its low-level mouse hook.
To include it in your project, download the compiled DLL and add it as a reference:
Right-click your project in the Solution Explorer and press Add Reference...
Go to the Browse tab.
Locate the InputHelper DLL-file, select it and press OK.
You can do all your logic in the hook's MouseWheel event handler, no need for the timer any longer:
Imports InputHelperLib
Public Class Form1
Dim WithEvents MouseHook As New InputHelper.Hooks.MouseHook
Private Sub MouseHook_MouseWheel(sender As Object, e As InputHelperLib.InputHelper.Hooks.MouseHookEventArgs) Handles MouseHook.MouseWheel
If MouseButtons.HasFlag(MouseButtons.Right) = True Then
'Do something...
End If
End Sub
End Class
There's no need to check e.Delta like you did because it will never be 0.

Move control to cursor location?

The think is I would like to show FlowLayoutPanel at mouse cursor location. But with my code bellow it only jumps around center of my form. I'm triggering it on DataGridView.CellMouseEnter event. Asking for some advice, thank you.
Private Sub dgw_CellMouseEnter(sender As Object, e As DataGridViewCellEventArgs) Handles dgw.CellMouseEnter
FlowLayoutPane1.Location = Cursor.Position
FlowLayoutPane1.Visible = True
End Sub
Use MouseMove instead of the MouseEnter event. MouseEnter is called only once when the mouse ENTERS the control.
Be aware that the MouseMove event fires even if the mouse location may be outside of the control.

How do I detect when i release mouse button in VB?

How do I detect when I release the left mouse button in a VB program?
So currently using:
Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
PictureBox1.Visible = True
End Sub
Means whenever I click my button the picturebox appears.
So how do I get the picturebox to disappear when I release the mouse button?
The click event will only occur after the the user releases the mouse button. A click occurs when the left mouse button is pressed and released.
You want to use the MouseDown and MouseUp events.

Button not hiding when mouse leaves from bottom

I have a form where I want buttons at the very bottom edge of the form, with no gap to the border. These buttons shall be "auto-hide", so they only show when the mouse is in for example the lower 20 pixels of the form. So I use the MouseMove event to trigger this, like code below. However, if mouse leaves the form across the bottom edge, where the buttons are, then the buttons will obviously remain. But I want them to hide. So I need for this purpose to hide the buttons by some other event. Hence I try to hide them in the form's MouseLeave event. But this makes the buttons unclickable and in an erratic state, flashing on and off when the mouse goes over the button.. Why is this? And how can I avoid this problem to get such autohide feature?
Private Sub ZgScale_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Y > Me.ClientSize.Height - 30 Then
Button1.Visible = True
Else
Button1.Visible = False
End If
End Sub
Private Sub ZgScale_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.MouseLeave
Button1.Visible = False
End Sub
The MouseLeave event fires when the mouse is no longer directly on that control (or form).
If the mouse moves on to a child control, the event will fire.
You need to check whether the mouse is no longer on the form, like this:
If Not Me.ClientRectangle.Contains(Me.PointToClient(e.Location)) Then
Button1.Visible = False
End If
EDIT: Fixed
Windows has direct support built-in for this scenario. Also exposed in Windows Forms and WPF. Once you get the MouseMove event, set the Capture property on the control to True. That forces all mouse messages to be directed to the control, even if the mouse moves outside of the control window.
Once you see it moving outside of the control bounds, set Capture back to false and hide your control. Beware that capture is turned off when the user clicks the mouse so you'll probably have to turn it back on afterwards. Although it should be automatic, you'll get another MouseMove event. Could fail if the user moves the mouse really fast.