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)

Syntax

[BrowsableAttribute(true)]
public event PreviewKeyDownEventHandler PreviewKeyDown
public:
[BrowsableAttribute(true)]
event PreviewKeyDownEventHandler^ PreviewKeyDown {
    void add(PreviewKeyDownEventHandler^ value);
    void remove(PreviewKeyDownEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member PreviewKeyDown : IEvent<PreviewKeyDownEventHandler,
    PreviewKeyDownEventArgs>
<BrowsableAttribute(True)>
Public Event PreviewKeyDown As PreviewKeyDownEventHandler

Remarks

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.

Examples

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)));
    }
}
Private Sub OvalShape1_PreviewKeyDown(
   ByVal sender As Object, 
   ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs
  ) Handles OvalShape1.PreviewKeyDown

    If e.KeyCode = Keys.F1 Then
        ' 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)))
    End If
End Sub

See Also

Shape Class
Microsoft.VisualBasic.PowerPacks Namespace
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)

Return to top