We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

There is no key down event in .NET panel control. The reason behind this is , panel does not get focus and cannot receive any windows message from keyboard. The controls which get focused can have handlers for different keyboard events such as key_up , key_down, key_press.
 
The following is workaround for handling keyboard event for panel controls .
[VB.NET CODE STARTS]
 
' On form load set the panel as active child control of the form.
 
Me.ActiveControl = pnlNameDetails  'name of the panel control , "Me" referes to the container form
 
' Create an event handler for panel control.
Private Sub Panel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pnlNameDetails.KeyDown
 
    If e.KeyCode = Windows.Forms.Keys.Escape Then
        Msgbox "Escape Key Is Pressed"   
    End If
 
End Sub

 
[VB.NET CODE ENDS]
That's it and now the keydown event can be captured from panel control.


Related Tags:

VB.NET

Author: Amrita Dash

top

VB.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login