共用方式為


Shape.PreviewKeyDown 事件

發生於之前KeyDown事件時按下按鍵和焦點是在圖形上。

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

語法

'宣告
<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 不支援事件。

備註

PreviewKeyDown事件可讓您攔截金鑰,並執行動作之前KeyDown就會發生事件。 處理這個事件中的任何金鑰不會傳遞到KeyDown事件。

如需如何處理事件的詳細資訊,請參閱處理和引發事件

範例

下列範例顯示如何回應PreviewKeyDown事件處理常式中的事件。 此範例中您需要OvalShape名 OvalShape1 為表單上的控制項。

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 安全性

請參閱

參考

Shape 類別

Microsoft.VisualBasic.PowerPacks 命名空間

其他資源

如何:使用 LineShape 控制項繪製線條 (Visual Studio)

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

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