2008-12-09 35 views

回答

31

而且多一點點:

private void button1_Click (object sender, EventArgs e) 
{   
    if((ModifierKeys & Keys.Control) == Keys.Control) 
    { 
     ControlClickMethod();  
    } 
    else 
    { 
     ClickMethod(); 
    } 
} 

private void ControlClickMethod() 
{ 
    MessageBox.Show("Control is pressed"); 
} 

private void ClickMethod() 
{ 
    MessageBox.Show ("Control is not pressed"); 
} 
+0

我感覺真的很愚蠢。我不知道ModifierKeys存在。多年來,我一直在做舊派(捕獲keydown並設置布爾值)。我想你每天都會學到新的東西。 :) – 2008-12-09 19:05:38

4

假設的WinForms,利用Control.ModifierKeys,如:

private void button1_Click(object sender, EventArgs e) { 
    MessageBox.Show(Control.ModifierKeys.ToString()); 
} 

假設WPF,使用Keyboard.Modifiers,如:

private void Button_Click(object sender, RoutedEventArgs e) { 
    MessageBox.Show(Keyboard.Modifiers.ToString()); 
} 
相關問題