陷阱WM_NCHITTEST消息但继续检查MouseEnter / -Leave

时间:2016-02-11 10:00:39

标签: vb.net winforms wndproc window-messages

我有一个表单,我已删除标题栏但保留了边框(请参阅this answer)。

在上面的回答中,声明需要将FormBorderStyle设置为SizableSizableToolWindow,并且为了阻止表单大小,您需要捕获WM_NCHITTEST事件。唯一的问题是,这样做会使引发正常的Form_MouseEnterForm_MouseLeave事件。

这有什么解决方法吗?

我的代码:

Protected Overrides Sub WndProc(ByRef message As Message)
    If message.Msg = &H84 Then 'WM_NCHITTEST
        Me.Focus() 'Focus the form when it receives a click.
        Return
    End If
    MyBase.WndProc(message)
End Sub

Private Sub PanelForm_MouseLeave(sender As Object, e As System.EventArgs) Handles PanelForm.MouseLeave
    PlaceOnScreen(False) 'Placed a breakpoint here, it won't execute.
End Sub

1 个答案:

答案 0 :(得分:3)

这只是一个错误,WM_NCHITTEST的返回值现在是0.这意味着"鼠标无处可及#34;。所以许多东西停止工作,比如激活和聚焦窗口和MouseEnter事件。你必须返回1(又名HTCLIENT),意思是"它在客户区":

case class DeptWithEmployees(department: Department, employees: Seq[Employee])

val result3: DeptWithEmployees = db.run(q.result).map { results =>
  results.groupBy(_._1).map {          // assumption that _._1 is your department id
    case (dept, grp) => DeptWithEmployees(dept, grp.map(_._2))
  }
}