Mousewheel scroll Event on a Label
-
Tuesday, February 28, 2012 2:42 PM
I have a regular WinForm Label, It is possible to determine when the Mousewheel is scrolling up or down. But just when the cursor is exactly above the label.
Thanks in Advance
All Replies
-
Tuesday, February 28, 2012 2:54 PMThe MouseEventArgs class has a Location property which should tell you where the cursor is when the event occurs.
Check out My Blog. Now updated to actually work!
-
Wednesday, February 29, 2012 8:31 AMbut hot to determine MouseScrollUp or MouseScrollDown?
-
Wednesday, February 29, 2012 4:07 PM
I did following and it worked for me perfectly
- I put label on form and created MouseHover and MouseLeave
events and stored in variable if mouse over the label or not
bool IsMouseOver = false; private void label1_MouseHover(object sender, EventArgs e) { IsMouseOver = true; } private void label1_MouseLeave(object sender, EventArgs e) { IsMouseOver = false; } - after I've created MouseWheel event for form, but not from properties window, from designer.cs
this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseWheel);
- Finally I put logic into Form1_MouseWheel Method
private void Form1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { if (IsMouseOver) { //do your logic here } }
To put everything together:
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { label1.Text = "This is label1 content"; } private void Form1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) { if (IsMouseOver) { //do your logic here } } bool IsMouseOver = false; private void label1_MouseHover(object sender, EventArgs e) { IsMouseOver = true; } private void label1_MouseLeave(object sender, EventArgs e) { IsMouseOver = false; } }
Please mark as read if helped.
Also visit my blog http://msguy.net/- Proposed As Answer by Michael Samteladze Thursday, March 01, 2012 8:50 AM
- Marked As Answer by Lie YouModerator Monday, March 05, 2012 2:48 AM
- I put label on form and created MouseHover and MouseLeave
events and stored in variable if mouse over the label or not
-
Wednesday, February 29, 2012 4:30 PM
Oh sorry, I misunderstood what you were asking.
For that, you should use the MouseEventArgs.Delta property. As it says in the documentation, Delta will be positive if the mouse was scrolled up (away from the user). If the mouse was scrolled down (toward the user) it will be a negative value instead.
Check out My Blog. Now updated to actually work!
- Proposed As Answer by Lie YouModerator Thursday, March 01, 2012 5:54 AM
- Marked As Answer by Lie YouModerator Monday, March 05, 2012 2:47 AM
-
Friday, March 02, 2012 10:27 PM
Michael, I may be misunderstanding, but I believe what you are proposing is overkill. If you capture the MouseWheel event on the label, it will only ever be triggered when the mouse is over the label. You don't really need to worry about handling MouseEnter and MouseLeave - those are only necessary if you are capturing the MouseWheel event at the Form level. Just subscribe to the MouseWheel event of the Label instead, and your event will be triggered correctly.Check out My Blog. Now updated to actually work!
- Marked As Answer by Lie YouModerator Monday, March 05, 2012 2:48 AM

