ButtonBase.OnKeyDown(KeyEventArgs) 方法

定義

引發 OnKeyUp(KeyEventArgs) 事件。Raises the OnKeyUp(KeyEventArgs) event.

protected:
 override void OnKeyDown(System::Windows::Forms::KeyEventArgs ^ kevent);
protected override void OnKeyDown (System.Windows.Forms.KeyEventArgs kevent);
override this.OnKeyDown : System.Windows.Forms.KeyEventArgs -> unit
Protected Overrides Sub OnKeyDown (kevent As KeyEventArgs)

參數

kevent
KeyEventArgs

KeyEventArgs,其中包含事件資料。A KeyEventArgs that contains the event data.

備註

引發事件會透過委派叫用此事件處理常式。Raising an event invokes the event handler through a delegate. 如需詳細資訊,請參閱 處理和引發事件For more information, see Handling and Raising Events.

OnKeyDown 方法也允許衍生類別處理事件,而不用附加委派。The OnKeyDown method also allows derived classes to handle the event without attaching a delegate. 這是在衍生類別中處理事件的慣用技巧。This is the preferred technique for handling the event in a derived class.

注意

OnKeyDown如果按鈕已停用,請不要呼叫 (這包括 OnKeyDown 當您在衍生類別中覆寫時,呼叫基類的方法 OnKeyDown) 。Do not call OnKeyDown if the button is disabled (this includes calls to the base class's OnKeyDown method when you override OnKeyDown in a derived class). 停用覆寫中的按鈕時 OnKeyDown ,請在停用按鈕之前呼叫基類的 OnKeyDown 方法,或完全不要呼叫。When disabling the button in an override of OnKeyDown, call the base class's OnKeyDown method before disabling the button, or do not call it at all.

給繼承者的注意事項

當在衍生類別中覆寫 OnKeyDown(KeyEventArgs) 時,請確定呼叫基底類別的 OnKeyDown(KeyEventArgs) 方法,使已註冊的委派能接收到事件。When overriding OnKeyDown(KeyEventArgs) in a derived class, be sure to call the base class's OnKeyDown(KeyEventArgs) method so that registered delegates receive the event.

適用於

另請參閱