Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture mouse wheel on panel?

How to capture mouse wheel on panel in C#? I'm using WinForms

EDIT:

I try to do it on PictureBox now.

My code:

this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);     this.pictureBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick); private void pictureBox1_MouseClick(object sender, MouseEventArgs e)     {       MessageBox.Show("Click");     } 

Clicking works. Wheelling doesn't. Why?

like image 841
Miko Kronn Avatar asked Dec 13 '10 14:12

Miko Kronn


People also ask

How do I make my mouse click the scroll wheel?

Go to the normal mouse tab, add a new button, go to the "click here to select mouse button" area and scroll the wheel. It will capture that action and you may assign it to what you want.

How can I use my scroll wheel without a mouse?

Move your fingers between the top and bottom of your touchpad to scroll up and down, or move your fingers across the touchpad to scroll sideways. Be careful to space your fingers a bit apart. If your fingers are too close together, they just look like one big finger to your touchpad.

Where is the scroll wheel on a mouse?

A mouse with a rubber or plastic wheel located between the left and right buttons (the "scroll wheel"). Also known as a "wheel mouse," when the wheel is moved back and forth, the active window is scrolled, eliminating the need to aim the pointer (cursor) at the scroll bar.


1 Answers

If you can't see the "MouseWheel" event on a component, then you need to create it manually. Also, we need to focus that component, otherwise the "MouseWheel" event will not work for that component. I will show you how to create a "MouseWheel" event for "pictureBox1" and how it works.

  1. INSIDE THE CONSTRUCTOR, create a mousewheel event on that component.

    InitializeComponent(); this.pictureBox1.MouseWheel += pictureBox1_MouseWheel; 
  2. CREATE THE FUNCTION manually. According to my example, call it "pictureBox1_MouseWheel"

    private void pictureBox1_MouseWheel(object sender, MouseEventArgs e) {     //you can do anything here } 
  3. CREATE a MouseHover event on that component (Go to properties in PicureBox1, select event, locate "MouseHover" and double-click the "MouseHover" event).

  4. CALL "Focus()"; method inside that MouseHover event.

    pictureBox1.Focus(); 
  5. Now run the program.

like image 182
Shehan Silva Avatar answered Sep 19 '22 00:09

Shehan Silva