No keydown event with picturebox...

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
I am using a picture box and need to determine when the user presses the delete button on the keyboard whilst their cursor is over my pictureBox. Normally I would use a keydown event, except this event does not exist for pictureBox control.

Can anyone help how I can do this?

Thanks in advance

Simon
 
Setting KeyPreview with the form you can use the forms keyboard events. There is also GetChildAtPoint method to help figure out if a PictureBox is pointed to. Example:
VB.NET:
Private Sub frmDiv_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    If e.KeyCode = Keys.Delete Then
        Dim c As Control = Me.GetChildAtPoint(Me.PointToClient(Cursor.Position))
        If TypeOf c Is PictureBox Then
            Me.Text = c.Name & " deleted"
        End If
    End If
End Sub
 
Back
Top