首先在窗體構造方法,里加入這樣一句話
C#代碼
1.this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
C#代碼
1.#region 進入窗體時加載
2.
3.public FormAlarmInfoQuery()
4.{
5. InitializeComponent();
6. pictureBox1.ImageLocation = "f:\\1.jpg";
7.
8. this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseWheel);
9. //判斷是否已安裝帶滾輪的鼠標
10. //SystemInformation.MouseWheelPresent.ToString();
11. //獲取鼠標滾輪在滾動時所獲得的行數
12. //SystemInformation.MouseWheelScrollLines.ToString();
13. //判斷該操作系統是否支持滾輪鼠標
14. //SystemInformation.NativeMouseWheelSupport.ToString();
15.}
16.
17.#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#代碼
1.private void panel1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
2.{
3. MessageBox.Show("滾動事件已被捕捉");
4. System.Drawing.Size t = pictureBox1.Size;
5. t.Width += e.Delta;
6. t.Height += e.Delta;
7. pictureBox1.Width = t.Width;
8. pictureBox1.Height = t.Height;
9.}
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;
}
如果輸出了“滾動事件已被捕捉”,那麼鼠標滾輪事件就成功被捕捉了,就可以在在裏邊寫讓鼠標滾輪處理的事件了
|