Shape.KeyDown Event


Occurs when a key is pressed and the shape has focus.

Namespace:   Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

public event KeyEventHandler KeyDown

Key events occur in the following order:




To handle keyboard events only at the form level and not enable shapes to receive keyboard events, set the Handled property in the form's KeyPress event-handling method to true.

For more information about how to handle events, see Handling and Raising Events.

The following example shows how to respond to the KeyDown event in an event handler to tab between shapes. This example requires that you have a RectangleShape control named RectangleShape1, an OvalShape control named OvalShape1, and a LineShape control named LineShape1 on a form.

private void Shapes_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    // Check to see whether the TAB key was pressed.
    if (e.KeyCode == Keys.Tab)
    // Call the Tab procedure
        Tab((Shape) sender);
private void Tab(Shape sender)
    // Select the next shape.
    sender.Parent.SelectNextShape(sender, true, true);
Return to top