當前位置:編程學習大全網 - 編程軟體 - winform中如何給button按鈕定義壹個單擊鼠標中鍵事件

winform中如何給button按鈕定義壹個單擊鼠標中鍵事件

button派生自control的,而control有壹個mousedown事件,可以判斷是哪壹個鍵被按下,下面是壹段摘抄自MSDN的代碼,妳可以參考壹下 private void panel1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

{

// Update the mouse path with the mouse information

Point mouseDownLocation = new Point(e.X, e.Y);

string eventString = null;

switch (e.Button) {

case MouseButtons.Left:

eventString = "L";

break;

case MouseButtons.Right:

eventString = "R";

break;

case MouseButtons.Middle:

eventString = "M";

break;

case MouseButtons.XButton1:

eventString = "X1";

break;

case MouseButtons.XButton2:

eventString = "X2";

break;

case MouseButtons.None:

default:

break;

}

  • 上一篇:數控CNC加工中心可以這樣做更賺錢?
  • 下一篇:寶馬2系多功能旅行車怎麽樣?值得買嗎?
  • copyright 2024編程學習大全網