vb中如何让鼠标经过隐藏的图片框后图片显示
2个回答
展开全部
因为隐藏的控件不能相应MouseMove时间,VB也没有提供MouseExit(鼠标移出)事件,所以只能使用以下方法模拟这个行为(这是我目前知道的唯一方法):
先把Picture1的Visible属性设置为False!
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If (X >= Picture1.Left And X <= Picture1.Left + Picture1.Width) And (Y >= Picture1.Top And Y <= Picture1.Top + Picture1.Height) And Picture1.Visible = False Then
'如果鼠标在Picture1所占据的范围内,且Picture1没有被显示
Picture1.Visible = True '显示Picture1
End If
End Sub
如果你还要模拟MouseExit(鼠标移出)的话,再添加如下代码:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Not ((X >= Picture1.Left And X <= Picture1.Left + Picture1.Width) And (Y >= Picture1.Top And Y <= Picture1.Top + Picture1.Height) And Picture1.Visible = True) Then
'如果鼠标不在Picture1所占据的范围内,且Picture1正在被显示
Picture1.Visible = False '隐藏Picture1
End If
End Sub
'注意:使用此段代码时有一个条件,就是Picture1不能和任何其它控件有重叠的部分,也不能让Picture1和任何其它控件相邻(距离=0),否则此段代码将不能正确地模拟MouseExit事件
对于Picture1的其它属性不予以讨论。如果还有问题追问我
展开全部
'窗体上添加图片框,放到窗体中间,边框和窗体要有边,否则不能判断是否移出...
Private Sub Form_Load()
Me.Caption = "0"
Picture1.BorderStyle = 0
Picture1.Picture = Nothing
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "0"
Picture1.Picture = Nothing
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "1"
Picture1.Picture = LoadPicture("要显示的图片全部地址")
End Sub
Private Sub Form_Load()
Me.Caption = "0"
Picture1.BorderStyle = 0
Picture1.Picture = Nothing
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "0"
Picture1.Picture = Nothing
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = "1"
Picture1.Picture = LoadPicture("要显示的图片全部地址")
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询