VB API中有没有识别鼠标状态的函数
我想在Picture控件中画一条有橡皮筋功能的直线,不想在VB的Picture1_MouseUp、Picture1_Mousedonw、Picture1_MouseMov...
我想在Picture控件中画一条有橡皮筋功能的直线,不想在VB的Picture1_MouseUp、Picture1_Mousedonw、Picture1_MouseMove中写代码,想把整个代码写到自定义的一个函数中,可是不知道API中有没有识别鼠标是在按下左键、移动、放开左键状态的函数,如果有,怎么使?对于能提供正确代码的网友先谢谢了!
这是我整的,但是运行时不对,在PICTURE上画线时,画出的线不是鼠标按下时的起点和终点,而且当鼠标移动时的那段橡皮筋代码不知怎么加了
Option Explicit
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim MousePos As POINTAPI
Dim startx, starty, endx, endy As Single
Dim line_state As Single
Private Sub Picture2_Click()
Call draw_line
End Sub
Private Sub draw_line()
If line_state = 1 Then
GetCursorPos MousePos
ClientToScreen Picture2.hwnd, MousePos
Picture2.AutoRedraw = False
startx = MousePos.X '记住起始点
starty = MousePos.Y
line_state = 2
ElseIf line_state = 2 Then '第二次单击记往终点
GetCursorPos MousePos
ClientToScreen Picture2.hwnd, MousePos
endx = MousePos.X '记住终止点
endy = MousePos.Y
Picture2.AutoRedraw = True
Picture2.Line (startx, starty)-(endx, endy) '最终画线
line_state = 1
Text3.Text = endx
Text4.Text = endy
End If
橡皮筋状态
End Sub 展开
这是我整的,但是运行时不对,在PICTURE上画线时,画出的线不是鼠标按下时的起点和终点,而且当鼠标移动时的那段橡皮筋代码不知怎么加了
Option Explicit
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim MousePos As POINTAPI
Dim startx, starty, endx, endy As Single
Dim line_state As Single
Private Sub Picture2_Click()
Call draw_line
End Sub
Private Sub draw_line()
If line_state = 1 Then
GetCursorPos MousePos
ClientToScreen Picture2.hwnd, MousePos
Picture2.AutoRedraw = False
startx = MousePos.X '记住起始点
starty = MousePos.Y
line_state = 2
ElseIf line_state = 2 Then '第二次单击记往终点
GetCursorPos MousePos
ClientToScreen Picture2.hwnd, MousePos
endx = MousePos.X '记住终止点
endy = MousePos.Y
Picture2.AutoRedraw = True
Picture2.Line (startx, starty)-(endx, endy) '最终画线
line_state = 1
Text3.Text = endx
Text4.Text = endy
End If
橡皮筋状态
End Sub 展开
2个回答
展开全部
VB事件里面有 MOUSE UP 和MOUSE DOWN 事件,就是鼠标按下事件。有一个参数BUTTON
1为左键。2为右键,3为中间键。
可以在里面加入
IF BUTTON =1 THEN
MSGBOX "你按下了鼠标左键!"
END IF
1为左键。2为右键,3为中间键。
可以在里面加入
IF BUTTON =1 THEN
MSGBOX "你按下了鼠标左键!"
END IF
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询