Поделиться через


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

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

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 Consuming 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 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
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)));
    }
}

.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)