简体   繁体   中英

open and close a form using the same keypress vb.net

I have form1 that whenever I press F1..

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
    If keyData = Keys.F1 Then
        Form2.Show()
        Return True
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)

End Function

form2 shows.. what I wanted is when form2 is up, and I press F1 again, it closes.
any idea? thanks

Just write the same code you wrote but in Form2 and say form2.close()

If keyData = Keys.F1 Then
    Form2.Close()
    Return True
End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM