'这两部分都没有反应,窗体没有标题栏,该怎样达到效果呀?Private Sub Form_GotFocus()
    '颜色变灰
    Label1.ForeColor = &H8000000F
End Sub
'--------------------------------------------Private Sub Form_LostFocus()
    '颜色变黑
    Label1.ForeColor = &H0&
End Sub

解决方案 »

  1.   

    Form.BorderStyle 属性为0时,
    不能够响应Form_GotFocus 和 Form_LostFocus 事件。
      

  2.   

    用API写回调函数,截获鼠标信息。
    SETWINDOWLONG 和一个回调函数。
      

  3.   

    可不可以写在Form_Activate、Deactivate 事件中来代替 :)
      

  4.   

    Form_Activate、Deactivate事件也不触发
      

  5.   

    设置BorderStyle属性为3,用SetWindowLong改变窗口风格:两个窗体:窗体2没有任何代码,默认设置,用做检验,启动对象为form1窗体一,一个标签,代码如下:Option ExplicitPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    '获取窗体结构信息函数
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const GWL_STYLE = (-16)
    Private Const WS_SYSMENU = &H80000
    Private Const WS_CAPTION = &HC00000
    Private Const WS_SIZEBOX = &H40000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    '为窗体指定一个新位置和状态函数
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Const SWP_NOZORDER = &H4
    Private Const SWP_FRAMECHANGED = &H20
    Private Const SWP_NOREPOSITION = &H200
    '获得整个窗体的大小和位置
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypePrivate Sub Form_Click()
    Form2.Show
    End SubPrivate Sub Form_Load()
        Dim lStyle As Long
        Dim MyRect As RECT
        Dim Change As Boolean
        '获取窗体的大小和位置
        GetWindowRect Me.hwnd, MyRect
        '取得当前窗体信息
        lStyle = GetWindowLong(Me.hwnd, GWL_STYLE)
        lStyle = lStyle And Not WS_SYSMENU
        lStyle = lStyle And Not WS_CAPTION
        lStyle = lStyle And Not WS_SIZEBOX
        lStyle = lStyle And Not WS_MAXIMIZEBOX
        lStyle = lStyle And Not WS_MINIMIZEBOX
        '按lStyle的值设置窗体信息
        SetWindowLong Me.hwnd, GWL_STYLE, lStyle
        '保持窗体的大小与位置不变
        SetWindowPos Me.hwnd, 0, MyRect.Left, MyRect.Top, MyRect.Right - MyRect.Left, MyRect.Bottom - MyRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
        
    End Sub
    Private Sub Form_GotFocus()
        '颜色变蓝 
       Label1.ForeColor = vbBlue
    End Sub
    '--------------------------------------------Private Sub Form_LostFocus()
        '颜色变绿
        Label1.ForeColor = vbGreen
    End Sub
      

  6.   

    事实上,BorderStyle=0也同样可以触发Form_GotFocus()和Form_LostFocus()事件
      

  7.   


    '新建工程,两个窗体
    Private Sub Form_GotFocus()
    MsgBox "got"
    End SubPrivate Sub Form_Load()
    Form2.Show
    End SubPrivate Sub Form_LostFocus()
    MsgBox "lost"
    End Sub