Sign in to follow this  
orbano

[.net] Mouse scroll event?

Recommended Posts

Hi! Is there a way to get this? I could not find it anywhere in the framework. Or a more specific problem: I want to prevent the comboBox from changing the selected item when scrolling with the mouse when its the active control. It can be really annoying in some cases. Thank you in advance!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think what you are talking about here is the scrolling with the mouse wheel?

If this is the case, then what you want to do is handle the WM_MOUSEWHEEL message, assuming you are developing using the WIN32 API using c++ of course.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I think what you are talking about here is the scrolling with the mouse wheel?

If this is the case, then what you want to do is handle the WM_MOUSEWHEEL message, assuming you are developing using the WIN32 API using c++ of course.


As this is the .NET forum, i'm programming the .NET framework (2.0), and with C#.

And yes, i need to capture the mouse wheel scrolling.

Share this post


Link to post
Share on other sites

public Form1()
{
InitializeComponent();

this.comboBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.MouseWheelScroll);

}

private void MouseWheelScroll(object sender, MouseEventArgs e)
{
Console.WriteLine("Mouse wheel scrolled");
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Machaira
*** Source Snippet Removed ***


Thank you! Why is it missing from the designer's property/event editor? Odd...

Oh and another question: How can i make the combobox not recieve the event and not change the SelectedItem?

Share this post


Link to post
Share on other sites
I have been looking at this and I have not found a way yet. Need to go do some stuff and I will look at it again when I get back.

theTroll

Share this post


Link to post
Share on other sites
Took a while put I found an answer for you.

Wow, for some reason comboBoxes do not work quiet right with the mouseWheel.


class NoScrollComboBox : System.Windows.Forms.ComboBox
{

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg != 0x20a) //WM_MOUSEWHEEL = &H20A
{
base.WndProc(ref m);
}
}
}




That should do it for you. Yeah not that pretty but will work.

theTroll

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this