本文介绍了如何将焦点移除到mousedown中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我试过按下鼠标按钮并将光标滑过控件,它会收到MouseDown事件。在进入另一个控件时不释放鼠标按钮,它会收到MouseDown事件。
类似于用手指滑过钢琴键的东西。
谢谢
我尝试过:
Hi
I tried that pressing the mouse button and slide the cursor over a control, it receives the MouseDown event. Without releasing the mouse button when entering another control, it receives the MouseDown event.
Something similar to slide your finger across the keys of a piano.
Thank you
Exemple
What I have tried:
'Programmed by Lekim'
Option Strict On
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")> _
Private Shared Sub mouse_event(ByVal dwFlags As UInteger, _
ByVal dx As UInteger, _
ByVal dy As UInteger, _
ByVal dwData As UInteger, _
ByVal dwExtraInfo As Integer)
End Sub
Dim lblkey(5) As Label
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim locLBL As New Point(10, 10)
Dim inc As Integer
For I As Integer = 0 To 5
lblkey(I) = New Label
lblkey(I).Size = CType(New Point(20, 100), Drawing.Size)
lblkey(I).BorderStyle = BorderStyle.FixedSingle
lblkey(I).Location = New Point(locLBL.X + inc, locLBL.Y)
Me.Controls.Add(lblkey(I))
inc += 19
Next
For I As Integer = 0 To 5
AddHandler lblkey(I).MouseDown, AddressOf lblkey_MouseDown
AddHandler lblkey(I).MouseUp, AddressOf lblkey_MouseUp
AddHandler lblkey(I).MouseMove, AddressOf lblkey_MouseMove
Next
End Sub
Private Sub lblkey_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim Index As Integer = Array.IndexOf(lblkey, sender)
Dim mPoint As New Point(Me.PointToClient(Cursor.Position).X, Me.PointToClient(Cursor.Position).Y)
Dim X As Integer = mPoint.X
If X < CInt(lblkey(Index).Left) Or
X > (CInt(lblkey(Index).Left) + _
CInt(lblkey(Index).Width)) Then
EventoUp()
EventoDown()
End If
End Sub
Private Sub lblkey_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim Index As Integer = Array.IndexOf(lblkey, sender)
If Button.MouseButtons = MouseButtons.Left Then
lblkey(Index).BackColor = Color.Azure
End If
End Sub
Private Sub lblkey_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim Index As Integer = Array.IndexOf(lblkey, sender)
lblkey(Index).BackColor = Color.Transparent
End Sub
End Class
Module modEventMouse
<DllImport("user32.dll")> _
Public Sub mouse_event(ByVal dwFlags As UInteger, _
ByVal dx As UInteger, _
ByVal dy As UInteger, _
ByVal dwData As UInteger, _
ByVal dwExtraInfo As Integer)
End Sub
<Flags()> _
Public Enum MouseEventFlags As UInteger
MOUSEEVENTF_ABSOLUTE = &H8000
MOUSEEVENTF_LEFTDOWN = &H2
MOUSEEVENTF_LEFTUP = &H4
MOUSEEVENTF_MIDDLEDOWN = &H20
MOUSEEVENTF_MIDDLEUP = &H40
MOUSEEVENTF_MOVE = &H1
MOUSEEVENTF_RIGHTDOWN = &H8
MOUSEEVENTF_RIGHTUP = &H10
MOUSEEVENTF_XDOWN = &H80
MOUSEEVENTF_XUP = &H100
MOUSEEVENTF_WHEEL = &H800
MOUSEEVENTF_HWHEEL = &H1000
End Enum
''' <summary>
''' Simulate MouseDown the left mouse button
''' </summary>
''' <remarks></remarks>
Public Sub EventoDown()
Call modEventMouse.mouse_event(MouseEventFlags.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
End Sub
''' <summary>
''' Simulate MouseUp the left mouse button
''' </summary>
''' <remarks></remarks>
Public Sub EventoUp()
Call modEventMouse.mouse_event(MouseEventFlags.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
End Sub
End Module
推荐答案
这篇关于如何将焦点移除到mousedown中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!