首先在表單構造方法,裡加入這樣一句話
C#代碼
- this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
C#代碼
- #region 進入表單時載入
-
- public FormAlarmInfoQuery()
- {
- InitializeComponent();
- pictureBox1.ImageLocation = "f:\\1.jpg";
-
- this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
- //判斷是否已安裝帶滾輪的滑鼠
- //SystemInformation.MouseWheelPresent.ToString();
- //擷取滑鼠滾輪在滾動時所獲得的行數
- //SystemInformation.MouseWheelScrollLines.ToString();
- //判斷該作業系統是否支援滾輪滑鼠
- //SystemInformation.NativeMouseWheelSupport.ToString();
- }
- #endregion
#region 進入表單時載入public FormAlarmInfoQuery(){InitializeComponent();pictureBox1.ImageLocation = "f:\\1.jpg"; this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel); //判斷是否已安裝帶滾輪的滑鼠//SystemInformation.MouseWheelPresent.ToString();//擷取滑鼠滾輪在滾動時所獲得的行數//SystemInformation.MouseWheelScrollLines.ToString();//判斷該作業系統是否支援滾輪滑鼠//SystemInformation.NativeMouseWheelSupport.ToString(); }#endregion
然後寫一個滑鼠事件方法
C#代碼
- private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
- {
- MessageBox.Show("滾動事件已被捕捉");
- System.Drawing.Size t = pictureBox1.Size;
- t.Width += e.Delta;
- t.Height += e.Delta;
- pictureBox1.Width = t.Width;
- pictureBox1.Height = t.Height;
- }
private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e){MessageBox.Show("滾動事件已被捕捉");System.Drawing.Size t = pictureBox1.Size;t.Width += e.Delta;t.Height += e.Delta;pictureBox1.Width = t.Width;pictureBox1.Height = t.Height;}
如果輸出了“滾動事件已被捕捉”,那麼滑鼠滾輪事件就成功被捕捉了,就可以在在裡邊寫讓滑鼠滾輪處理的事件了