vb.net怎么让鼠标不动三秒之后隐藏控件?
我先在模块前声明DimHideTimeAsSingle,然后在窗体的MouseMove事件中让控件显示,在定时器中HideTime+=1,当大于等于3时隐藏控件,所以就是...
我先在模块前声明Dim HideTime As Single,然后在窗体的MouseMove事件中让控件显示,在定时器中HideTime+=1,当大于等于3时隐藏控件,所以就是鼠标在窗体上移动时显示控件,鼠标不动或移出窗体三秒后隐藏控件。可问题来了,即使鼠标悬停在窗体上,也会触发窗体的MouseMove事件,所以控件会隐藏后又立刻显示,这可怎么办啊,我看那些一般的音乐视频软件都能做到,怎么办呢?
展开
3个回答
展开全部
我测试可以用, 你试下,以下代码要隐藏的控件是button1,从button1上第一次移到窗体上会无效,鼠标停留在button1上无效
Private xy As Point
Private data As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Dim back As Point = Me.PointToClient(Control.MousePosition)
If xy = back Then Timer1.Enabled = True : Exit Sub
Button1.Visible = True
xy = back
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
data = data + 1
If data = 3 Then Button1.Visible = False : Timer1.Enabled = False : data = 0
End Sub
Private xy As Point
Private data As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Dim back As Point = Me.PointToClient(Control.MousePosition)
If xy = back Then Timer1.Enabled = True : Exit Sub
Button1.Visible = True
xy = back
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
data = data + 1
If data = 3 Then Button1.Visible = False : Timer1.Enabled = False : data = 0
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在MouseMove事件中加一句:
HideTime=0
HideTime=0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询