Shape.KeyPress 事件
發生於按下按鍵且焦點在圖形時。
命名空間: Microsoft.VisualBasic.PowerPacks
組件: Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)
語法
'宣告
<BrowsableAttribute(True)> _
Public Event KeyPress As KeyPressEventHandler
[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 不支援事件。
備註
主要事件發生順序如下:
KeyPress
KeyPress非字元的索引鍵,不會引發事件不過,非字元的索引鍵並引發KeyDown和KeyUp事件。
使用KeyChar範例在執行階段,以取用或修改子集常見按鍵的按鍵輸入的屬性。
若要處理鍵盤事件只能在表單層級並不會啟用接收鍵盤事件的圖形,設定Handled屬性在表單的KeyPress事件處理方法來true。
如需如何處理事件的詳細資訊,請參閱處理和引發事件。
範例
下列範例顯示如何回應KeyPress事件處理常式中的事件。 此範例中您需要RectangleShape名 RectangleShape1 為表單上的控制項。
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。
請參閱
參考
Microsoft.VisualBasic.PowerPacks 命名空間
其他資源
如何:使用 LineShape 控制項繪製線條 (Visual Studio)