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 KeyPressEventHandler KeyPress
public:
[BrowsableAttribute(true)]
event KeyPressEventHandler^ KeyPress {
void add(KeyPressEventHandler^ value);
void remove(KeyPressEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member KeyPress : IEvent<KeyPressEventHandler,
KeyPressEventArgs>
<BrowsableAttribute(True)>
Public Event KeyPress As KeyPressEventHandler
Remarks
Key events occur in the following order:
KeyPress
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 Handling and Raising 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 void rectangleShape1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
char ch;
ch = e.KeyChar;
MessageBox.Show("You pressed the " + ch + " key.");
}
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
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