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
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 }
下面是鼠标控制音乐播放器音量事件
1 public Form1() 2 { 3 InitializeComponent(); 4 this.btnjin.MouseWheel += new MouseEventHandler(btnjin_MouseWheel); 5 6 } 7 int m1=30; 8 private void btnjin_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) 9 { 10 if(m1>=0&&m1<=100) 11 { 12 m1 += e.Delta / 24; 13 if (m1 > 100) 14 { 15 m1 = 100; 16 } 17 else if (m1 < 0) 18 { 19 m1 = 0; 20 } 21 lblvol.Width = (60 / 20) * m1 / 5; 22 Music.settings.volume = m1 ; 23 } 24 25 26 } 27 28 private void btnjin_MouseEnter(object sender, EventArgs e) 29 { 30 panel2.Visible = true; 31 } 32 33 private void btnjin_MouseLeave(object sender, EventArgs e) 34 { 35 panel2.Visible = false; 36 }