I would like to prevent scrolling in comboboxes when the mouse is over the combobox (mouse over). I have already tried the following solution, but it only stops scrolling in the combobox when it is expanded.
Asked
Active
Viewed 473 times
0
-
What is the type of your project? The linked project is wpf, but you use the winforms tag here. – 大陸北方網友 Feb 05 '21 at 07:45
-
It's a plain Windows Forms App but the answer is also working for UserControls in Winfroms (https://stackoverflow.com/a/1883072/5586390) – br0ken.pipe Feb 05 '21 at 08:05
-
I tested it, and it works(combobox is not expanded). What is the `UserControls` in your comment? – 大陸北方網友 Feb 05 '21 at 08:13
-
Did you add the event handler? It's not listed in the PropertyGrid (it's set to `[Browsable(false)]`). You have to add it manually, in the Constructor of the Parent's Form (or whatever other Window is hosting it). Can you show what you did? – Jimi Feb 05 '21 at 08:41
2 Answers
0
You will need to extend the ComboBox
control, and surppress the MouseWheel message.
Something like this:
public class ComboBoxEx : ComboBox
{
protected override void WndProc(ref Message m)
{
if (m.Msg == 522 /* WM_MOUSEWHEEL */)
{
return;
}
base.WndProc(ref m);
}
}

D.Kastier
- 2,640
- 3
- 25
- 40
0
public static void Combo_MouseWheel(object sender, MouseEventArgs e)
{
ComboBox cmb = (ComboBox)sender;
if (!cmb.DroppedDown)
{
((HandledMouseEventArgs)e).Handled = true;
//this.Focus();
}
}

MAGA Computers
- 1
- 1