Pergunta

My application is parent, child application. Child forms shows then press cntrl + F4 the child form is closed. How to block the action and the same time if i press cntrl + F4 the child form have submit button that event is invoked.

How can i do that?

I am using below coding is block the control + F4

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        If keyData = Keys.Control Or Keys.F4 Then Return True
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
Foi útil?

Solução

This event already exists, the FormClosing event fires. You can cancel the close by setting e.Cancel = True in your event handler for the event. Be sure to check the e.CloseReason before you do that.

Do avoid breaking standard Windows shortcut keystrokes, there is no point. The user can also close the window by clicking the child window's Close button. Ctrl+F4 is just a helpful shortcut to do the same thing without using the mouse.

Outras dicas

You have to catch the form closing event, then test if it's done by key-press.

I assume you mean ALT-F4?

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
          If My.Computer.Keyboard.AltKeyDown Then e.Cancel = True
    End Sub

Or even shorter;

    e.Cancel=My.Computer.Keyboard.AltKeyDown
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top