using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace demo9 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_KeyDown(object sender, KeyEventArgs e) { MessageBox.Show("按動的鍵為:" + e.KeyCode.ToString()); } private void Form1_MouseDown(object sender, MouseEventArgs e) { //響應鼠標的不同按鍵 if (e.Button == MouseButtons.Left) { MessageBox.Show("按動鼠標左鍵!"); } if (e.Button == MouseButtons.Middle) { MessageBox.Show("按動鼠標中鍵!"); } if (e.Button == MouseButtons.Right) { MessageBox.Show("按動鼠標右鍵!"); } } private void Form1_MouseMove(object sender, MouseEventArgs e) { this.Text = "當前鼠標的位置為:( " + e.X + " , " + e.Y + ")"; } } }