我试图让我的程序最小化并在按键时最大化(我使用h键)。
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Select Case e.KeyChar
Case "h"
If Me.WindowState = FormWindowState.Maximized Then
Me.WindowState = FormWindowState.Minimized
ElseIf Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Maximized
End If
End Select
End Sub
End Class
我不明白为什么它会赢得'工作
答案 0 :(得分:0)
嗯,也许它不起作用,因为你的表格不处于最大化状态或最小化状态。总之,也许你的表格处于正常状态。先试试这个步骤。
1st:将表单的键预览设置为True。 然后在你的代码中:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Select Case e.KeyChar
Case "h"
If Me.WindowState = FormWindowState.Maximized Then
Me.WindowState = FormWindowState.Minimized
ElseIf Me.WindowState = FormWindowState.Minimized Then
Me.WindowState = FormWindowState.Maximized
else
Me.WindowState = FormWindowState.Minimized 'add this.
End If
End Select
End Sub
如果此代码无效,请尝试将其转移到按键事件。 希望这能解决你的问题。