QueryContinueDragEventArgs.KeyState 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會取得 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.Show訊息替換Console.WriteLine為或附加於多行TextBox。
要執行範例程式碼,將它貼到包含繼承自 Control的型別實例的專案中,例如 a Button 或 ComboBox。 接著命名實例 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 | 鑰匙 |
|---|---|
| 1 | 滑鼠左鍵。 |
| 2 | 右滑鼠按鈕。 |
| 4 | SHIFT 鍵 |
| 8 | CTL鑰匙。 |
| 16 | 滑鼠中鍵。 |
| 32 | ALT 鍵 |
預設情況下, QueryContinueDrag 事件會設 Action 為 , DragAction.Drop 如果 KeyState 表示左、中、右滑鼠按鈕被按下。