CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 1999
    Location
    CA
    Posts
    83

    Detecting when Delete key is pressed

    Ok, I have set my form's key preview value to true and have modified the Form_KeyPress event sub, however I can't get it to find when the user presses the Delete key. All normal letters and numbers seem to get detected, but the delete key isn't for some reason.

    Here's a little test Sub I wrote it just checks if the user hits delete and if something is selected in a list box it will delete that item:

    Private Sub Form_KeyPress(KeyAscii As Integer)
    Dim i As Integer
    MsgBox ("YOU HAVE PRESSED " & Chr(KeyAscii))
    If KeyAscii = 46 Then
    For i = main_list.ListCount - 1 To 0 Step -1
    If main_list.Selected(i) Then
    main_list.RemoveItem (i)
    End If
    Next i
    End If
    End Sub

    Any help would be greatly appreciated. Thanks in advance.


  2. #2
    Join Date
    Dec 1999
    Location
    Dallas, Texas, USA
    Posts
    59

    Re: Detecting when Delete key is pressed

    Put it under:

    private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)
    If KeyCode = 46 then
    MsgBox "Delete was pressed", , App.Title
    End If
    End Sub





    --
    Chizl
    [email protected]
    http://www.chizl.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured