مشاركة عبر


Shape.KeyPress 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

'إقرار
<BrowsableAttribute(True)> _
Public Event KeyPress As KeyPressEventHandler
'الاستخدام
Dim instance As Shape
Dim handler As KeyPressEventHandler

AddHandler instance.KeyPress, handler
[BrowsableAttribute(true)]
public event KeyPressEventHandler KeyPress
[BrowsableAttribute(true)]
public:
 event KeyPressEventHandler^ KeyPress {
    void add (KeyPressEventHandler^ value);
    void remove (KeyPressEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member KeyPress : IEvent<KeyPressEventHandler,
    KeyPressEventArgs>
JScript does not support events.

Remarks

Key events occur in the following order:

KeyDown

KeyPress

KeyUp

The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.

Use the KeyChar property to sample keystrokes at run time and to consume or modify a subset of common keystrokes.

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 KeyPress event in an event handler. This example requires that you have a RectangleShape control named RectangleShape1 on a form.

Private Sub RectangleShape1_KeyPress(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.KeyPressEventArgs
  ) Handles RectangleShape1.KeyPress

    Dim ch As Char
    ch = e.KeyChar
    MsgBox("You pressed the " & ch & " key.")
End Sub
private void rectangleShape1_KeyPress(object sender, 
    System.Windows.Forms.KeyPressEventArgs e)
{
    char ch;
    ch = e.KeyChar;
    MessageBox.Show("You pressed the " + ch + " key.");
}

.NET Framework Security

See Also

Reference

Shape Class

Shape Members

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)