Shape.PreviewKeyDown Event

 

Occurs before the KeyDown event when a key is pressed and focus is on the shape.

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

[BrowsableAttribute(true)]
public event PreviewKeyDownEventHandler PreviewKeyDown

The PreviewKeyDown event enables you to intercept keys and perform actions before the KeyDown event occurs. Any keys handled in this event will not be passed on to the KeyDown event.

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

The following example shows how to respond to the PreviewKeyDown event in an event handler. This example requires that you have an OvalShape control named OvalShape1 on a form.

private void ovalShape1_PreviewKeyDown(object sender, 
    System.Windows.Forms.PreviewKeyDownEventArgs e)
{
    if (e.KeyCode == Keys.F1)
    // Display a pop-up Help window to assist the user.
    {
        Help.ShowPopup(ovalShape1.Parent, 
            "This shape represents a network node.", 
            PointToScreen(new Point(ovalShape1.Width, ovalShape1.Height)));
    }
}
Return to top
Show: