2009-02-05 72 views
6

我想在點擊鼠標滾輪時關閉選項卡控件中的選項卡。如何在WPF中捕獲此事件?如何處理WPF中的鼠標滾輪點擊事件?

編輯: 下面的代碼:

private void tabMain_MouseDown(object sender, MouseButtonEventArgs e) 
    { 
     if(e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed) 
     { 
      MessageBox.Show("Middle button clicked"); 
     } 
    } 

回答

9

鼠標滾輪實際上是MiddleButton,所以對於在MouseDown事件轉盤點擊病情ChangedButton ==中東& & ButtonState ==按下

+0

是否有理由在** MouseDown **事件中檢查ButtonState == ButtonState.Pressed?或者它只是從某處複製/粘貼的? – Sinatr 2014-08-19 08:21:33

3

更簡單的解決方案

if(e.MiddleButton){MessageBox.Show(「Middle button clicked」); }