Category / Section
How to detect whether a 'CTRL' key or a 'SHIFT' key is down in WinForms GridControl?
1 min read
Handle the Shift and Ctrl key
To know whether the CTRL or SHIFT key is currently down or not, you can find out by using the following codes.
C#
void gridControl1_MouseDown(object sender, MouseEventArgs e) { // Checks whether the Ctrl key is down. if ((Control.ModifierKeys & Keys.Control) != 0) { Console.WriteLine("Control Key is down"); } //Checks whether the Shift key is down. if ((Control.ModifierKeys & Keys.Shift) != 0) { Console.WriteLine("Shift Key is down"); } }
VB
Private Sub gridControl1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) 'Checks whether the Ctrl key is down. If (Control.ModifierKeys And Keys.Control) <> 0 Then Console.WriteLine("Control Key is down") End If 'Checks whether the Shift key is down. If (Control.ModifierKeys And Keys.Shift) <> 0 Then Console.WriteLine("Shift Key is down") End If End Sub
Figure 1: Grid Control with Shift and Control keys handling
Samples: