[.net] Mouse scroll event?

Started by
5 comments, last by TheTroll 17 years, 1 month ago
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!
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
Advertisement
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.
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.
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
        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");        }

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

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?
"Knowledge is no more expensive than ignorance, and at least as satisfying." -Barrin
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
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

This topic is closed to new replies.

Advertisement