QueryContinueDragEventArgs.KeyState 屬性

定義

取得 SHIFT、CTRL 和 ALT 鍵的目前狀態。

public:
 property int KeyState { int get(); };
public int KeyState { get; }
member this.KeyState : int
Public ReadOnly Property KeyState As Integer

屬性值

SHIFT、CTRL 和 ALT 鍵的目前狀態。

範例

下列程式碼範例示範此成員的使用。 在此範例中,事件處理常式會報告事件發生次數 Control.QueryContinueDrag 。 此報告可協助您瞭解事件發生的時間,並可協助您進行偵錯。 若要報告多個事件或經常發生的事件,請考慮將 取代 MessageBox.ShowConsole.WriteLine 為 或將訊息附加至多行 TextBox

若要執行範例程式碼,請將它貼到包含繼承自 Control 之型別實例的專案,例如 ButtonComboBox 。 然後命名 實例 Control1 ,並確定事件處理常式與事件相關聯 Control.QueryContinueDrag

private void Control1_QueryContinueDrag(Object sender, QueryContinueDragEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "KeyState", e.KeyState );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "EscapePressed", e.EscapePressed );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Action", e.Action );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "QueryContinueDrag Event" );
}
Private Sub Control1_QueryContinueDrag(sender as Object, e as QueryContinueDragEventArgs) _ 
     Handles Control1.QueryContinueDrag

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "KeyState", e.KeyState)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "EscapePressed", e.EscapePressed)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Action", e.Action)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"QueryContinueDrag Event")

End Sub

備註

屬性中 KeyState 設定的位會識別作業期間按下的按鍵或滑鼠按鍵。 例如,如果按下滑鼠左鍵,則會設定 屬性中的 KeyState 第一個位。 您可以使用位 AND 運算子來測試指定的索引鍵狀態。

下表列出為指定事件設定的位。

bit Key
1 滑鼠左鍵。
2 滑鼠右鍵。
4 SHIFT 鍵。
8 CTL 機碼。
16 滑鼠中鍵。
32 ALT 鍵。

根據預設, QueryContinueDrag 事件會設定 ActionDragAction.Drop 為 ,表示 KeyState 按下左、中間或滑鼠右鍵。

適用於

另請參閱