VB如何判断鼠标指针是否指着按钮
我想自己制作按钮,用一个标签控件,鼠标指向它时背景为绿色,点击它为黄色,鼠标不指向它时为红色。(就是跟按钮一样了,只不过用代码体现)其实我最关心的是如何判断鼠标指针是否指...
我想自己制作按钮,用一个标签控件,鼠标指向它时背景为绿色,点击它为黄色,鼠标不指向它时为红色。(就是跟按钮一样了,只不过用代码体现)其实我最关心的是如何判断鼠标指针是否指着它,因为这是自制按钮的关键。谢谢! (就是按钮效果啦!用form1_mousemove是不行的)
展开
展开全部
鼠标指向它时背景为绿色,在Label1的MouseMove事件设置其背景色为绿。
点击它为黄色,这句不好理解。如果是鼠标点下时改变的话,应在Label1的MouseDown事件中设置Label1的背景色,但放开鼠标时又会恢复为绿色。
不指向时为红色,可以在Form1的MouseMove事件中设置Label1的背景色为红。
“其实我最关心的是如何判断鼠标指针是否指着它”,很简单,判定指着它就是Label1自己的MouseMove事件,判定没有指着它,就是Form1的MouseMove事件
点击它为黄色,这句不好理解。如果是鼠标点下时改变的话,应在Label1的MouseDown事件中设置Label1的背景色,但放开鼠标时又会恢复为绿色。
不指向时为红色,可以在Form1的MouseMove事件中设置Label1的背景色为红。
“其实我最关心的是如何判断鼠标指针是否指着它”,很简单,判定指着它就是Label1自己的MouseMove事件,判定没有指着它,就是Form1的MouseMove事件
展开全部
用MouseMove事件和mousedown事件来定义就可以了啊。
代码如下:
Private
Declare
Function
SetCapture
Lib
"user32"
(ByVal
hwnd
As
Long)
As
Long
Private
Declare
Function
ReleaseCapture
Lib
"user32"
()
As
Long
Private
Sub
Command1_MouseDown(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
Label1.BackColor
=
RGB(255,
255,
0)
End
Sub
Private
Sub
Command1_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
SetCapture
Command1.hwnd
If
X
>
0
And
X
<=
Command1.Width
And
Y
>
0
And
Y
<
Command1.Height
Then
Label1.BackColor
=
vbGreen
Else
Label1.BackColor
=
vbRed
ReleaseCapture
End
If
End
Sub
代码如下:
Private
Declare
Function
SetCapture
Lib
"user32"
(ByVal
hwnd
As
Long)
As
Long
Private
Declare
Function
ReleaseCapture
Lib
"user32"
()
As
Long
Private
Sub
Command1_MouseDown(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
Label1.BackColor
=
RGB(255,
255,
0)
End
Sub
Private
Sub
Command1_MouseMove(Button
As
Integer,
Shift
As
Integer,
X
As
Single,
Y
As
Single)
SetCapture
Command1.hwnd
If
X
>
0
And
X
<=
Command1.Width
And
Y
>
0
And
Y
<
Command1.Height
Then
Label1.BackColor
=
vbGreen
Else
Label1.BackColor
=
vbRed
ReleaseCapture
End
If
End
Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
form1_mousemove?
object.name is form1?
if object.name is not form1 then
private sub object.name_mousemove()
object.name.backcolor =green
end if
private sub object.name_click()
object.name.backcolor=yellow
end sub
private sub object.name_lostfocus()
object.name.backcolor=red
end sub
object.name is form1?
if object.name is not form1 then
private sub object.name_mousemove()
object.name.backcolor =green
end if
private sub object.name_click()
object.name.backcolor=yellow
end sub
private sub object.name_lostfocus()
object.name.backcolor=red
end sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用控件的MOUSEMOVE事件
如 Label1_MouseMove
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbRed
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbYellow
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbGreen
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbGreen
End Sub
如 Label1_MouseMove
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbRed
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbYellow
End Sub
Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbGreen
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = vbGreen
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = RGB(255, 255, 0)
End Sub
Private Sub Label1_DblClick()
Label1.BackColor = RGB(0, 0, 0)
Label1.BackColor = RGB(0, 255, 0)
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = RGB(255, 0, 0)
End Sub
'单击事件可能伴随着MOUSEMOVE所以改成双击,颜色值你自己修改下
Label1.BackColor = RGB(255, 255, 0)
End Sub
Private Sub Label1_DblClick()
Label1.BackColor = RGB(0, 0, 0)
Label1.BackColor = RGB(0, 255, 0)
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = RGB(255, 0, 0)
End Sub
'单击事件可能伴随着MOUSEMOVE所以改成双击,颜色值你自己修改下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询