none
How To Enable Hot-Keys

    Question

  • I am developing an application in VB.Net.I have a windows form with several buttons like Save,Exit,Delete etc.When the user Press Ctrl+S:Data must Save similarly Ctrl+E:Data must Exit, Ctrl+D:Data must Delete.How to Do this Requirement in Windows Form Using VB.NET.


    Alluru.Midhun Kumar Singh


    Wednesday, May 04, 2011 10:39 AM

Answers

  • Please use the below code:

      Dim altPressed As Boolean = False
      Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, keyData As System.Windows.Forms.Keys) As Boolean
    
        If altPressed Then
          altPressed = False
          If msg.WParam.ToInt32() = CInt(Keys.S) Then
            ' TO DO ...
            Console.WriteLine("Alt+S is pressed")
    
          End If
        End If
    
        If msg.WParam.ToInt32() = &H12 Then 'Alt Key
          altPressed = True
    
          Console.WriteLine("Alt is pressed")
        End If
    
        Return MyBase.ProcessCmdKey(msg, keyData)
      End Function
    


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 16, 2011 3:36 PM

All replies