问题是每个控件都有它自己的双击事件,所以如果你双击窗体上的一个面板,窗体的双击事件不会被触发。
但是,您可以添加MessageFilter,例如
Public Class Minimizer
Implements IMessageFilter
Private Const WM_LBUTTONDBLCLK As Integer = &H203
ReadOnly _form As Form
Public Sub New(f As Form)
_form = f
End Sub
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
If m.Msg = WM_LBUTTONDBLCLK Then
_form.WindowState = FormWindowState.Minimized
End If
Return False
End Function
End Class
和一个小测试:
Private Sub Main()
Dim f = New Form()
f.Controls.Add(New Panel() With { .Dock = DockStyle.Fill })
Application.AddMessageFilter(New Minimizer(f))
f.ShowDialog()
End Sub
但是我认为如果双击任何地方最小化表单,那将是一种奇怪的用户体验......