我正在使用VB.NET,想知道如何双击表单以最小化它。
我有以下代码,但它不起作用:
Private Sub openPROJECTS_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseDoubleClick
'Minimize the form
Me.WindowState = FormWindowState.Minimized
End Sub
我正在使用VB.NET。
答案 0 :(得分:0)
问题是每个控件都有自己的双击事件,所以如果你双击例如在您的表单上,您的表单的双击事件不会被解雇。
但是,您可以添加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
但我认为如果双击任何地方最小化表格,那将是一种奇怪的用户体验......