想要获得一种效果:
1.鼠标由窗体的空白处转移到控件上触发的,名称比如是form_mouseout
2.鼠标由窗体的控件转移到空白处上触发的,名称比如是form_mouseon
3.这两种事件都只在状态变化的时候触发一次,只运行代码一次,不会说,比如鼠标在空白处一直触发form_mouseon不知道解释清楚没。
另外问下能不能自己编写事件,而不是只限于VB中提供的。谢谢!

解决方案 »

  1.   

    试试看下面的Option Explicit
    Dim bOn As BooleanPrivate Sub Form_Load()
        bOn = True
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If bOn = False Then
            MsgBox "world"
        End If
        bOn = True
    End SubPrivate Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If bOn = True Then
            MsgBox "hello"
        End If
        bOn = False
    End Sub
      

  2.   

    下面代码即可Option Explicit
    Dim iOld As Integer
    Dim iNew As IntegerPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        iNew = 1
        If iNew <> iOld Then
            Form1.Cls
            Print "Command1"
        End If
        iOld = iNew
    End SubPrivate Sub Form_Load()
        iOld = 0
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        iNew = 0
        If iNew <> iOld Then
            Form1.Cls
            Print "Form"
        End If
        iOld = iNew
    End SubPrivate Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        iNew = 2
        If iNew <> iOld Then
            Form1.Cls
            Print "Frame1"
        End If
        iOld = iNew
    End SubPrivate Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        iNew = 3
        If iNew <> iOld Then
            Form1.Cls
            Print "Label1"
        End If
        iOld = iNew
    End Sub
      

  3.   

    1、窗体和控件都有:Mouse_Move事件
    2、当鼠标移动到控件上时,会触发控件的Mouse_Move事件
    3、当鼠标移动到窗体上时,会触发窗体的Mouse_Move事件根据以上的提示,你可以组织自己的程序
      

  4.   

    谁会写MouseOut事件 麻烦给段代码
    谢谢了!
      

  5.   

    用mousemove当然也可以,只是如果控件多了就麻烦了。最后把控件弄成了数组的,可是编写代码就麻烦了,不能知道控件代表什么。
    另外控件数组与一个一个控件检测相比运行次数会不会多些?还有,其实mousemove是一直都在触发的事件,不符合我的第三条要求。
    最后,还没人告诉我能不能自己编写事件。