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)

Syntax

'Declaration
<BrowsableAttribute(True)> _
Public Event KeyDown As KeyEventHandler
[BrowsableAttribute(true)]
public event KeyEventHandler KeyDown
[BrowsableAttribute(true)]
public:
 event KeyEventHandler^ KeyDown {
    void add (KeyEventHandler^ value);
    void remove (KeyEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member KeyDown : IEvent<KeyEventHandler,
    KeyEventArgs>
JScript does not support events.

Remarks

Key events occur in the following order:

KeyDown

KeyPress

KeyUp

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 Consuming Events.

Examples

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 Sub Shapes_KeyDown(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.KeyEventArgs
  ) Handles RectangleShape1.KeyDown, OvalShape1.KeyDown, 
            LineShape1.KeyDown

    ' Check to see whether the TAB key was pressed.
    If e.KeyCode = Keys.Tab Then
        ' Call the Tab procedure
        Tab(sender)
    End If
End Sub
Private Sub Tab(ByVal sender As Shape)
    ' Select the next shape.
    sender.Parent.SelectNextShape(sender, True, True)
End Sub
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);
}

.NET Framework Security

See Also

Reference

Shape Class

Microsoft.VisualBasic.PowerPacks Namespace

Other Resources

How to: Draw Lines with the LineShape Control (Visual Studio)

How to: Draw Shapes with the OvalShape and RectangleShape Controls (Visual Studio)

Introduction to the Line and Shape Controls (Visual Studio)