共用方式為


Shape.KeyDown 事件

按下按鍵且形狀取得焦點時發生。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

'宣告
<BrowsableAttribute(True)> _
Public Event KeyDown As KeyEventHandler
[BrowsableAttribute(true)]
public event KeyEventHandler KeyDown
[BrowsableAttribute(true)]
public:
 event KeyEventHandler^ KeyDown {
    void add (KeyEventHandler^ value);
    void remove (KeyEventHandler^ value);
}
[<BrowsableAttribute(true)>]
member KeyDown : IEvent<KeyEventHandler,
    KeyEventArgs>
JScript 不支援事件。

備註

按鍵事件依下列順序發生:

KeyDown

KeyPress

KeyUp

若要處理只會在表單層次的鍵盤事件,並不啟動圖形收到鍵盤事件,設定Handled屬性在表單中的KeyPress事件處理方法,以true。

如需如何處理事件的詳細資訊,請參閱使用事件

範例

下列範例會示範如何回應KeyDown事件處理常式至圖形之間的索引標籤中的事件。這個範例要求您必須RectangleShape控制項名為 RectangleShape1, OvalShape名為 OvalShape1,控制項和LineShape控制項的表單上命名為 LineShape1。

Private Sub Shapes_KeyDown(
    ByVal sender As Object, 
    ByVal e As System.Windows.Forms.KeyEventArgs
  ) Handles RectangleShape1.KeyDown, OvalShape1.KeyDown, 
            LineShape1.KeyDown

    ' Check to see whether the TAB key was pressed.
    If e.KeyCode = Keys.Tab Then
        ' Call the Tab procedure
        Tab(sender)
    End If
End Sub
Private Sub Tab(ByVal sender As Shape)
    ' Select the next shape.
    sender.Parent.SelectNextShape(sender, True, True)
End Sub
private void Shapes_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
    // Check to see whether the TAB key was pressed.
    if (e.KeyCode == Keys.Tab)
    // Call the Tab procedure
    {
        Tab((Shape) sender);
    }
}
private void Tab(Shape sender)
{
    // Select the next shape.
    sender.Parent.SelectNextShape(sender, true, true);
}

.NET Framework 安全性

請參閱

參考

Shape 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

HOW TO:使用 LineShape 控制項繪製線條 (Visual Studio)

HOW TO:使用 OvalShape 和 RectangleShape 控制項繪製圖案 (Visual Studio)

Line 和 Shape 控制項簡介 (Visual Studio)