MouseWheel event

G

Guest

I have a window vertically splitted in two parts : on the left a panel containing controls (including a combobox)
and on the right a panel with scrollbars to display an image.
I wish that MouseWheel events act on the scrollbars to position the image
but MouseWheel events are send to the combobox.
I add a MouseEventHandler to the combobox,
comboBox1.MouseWheel += new MouseEventHandler(comboBox1_MouseWheel)
and add the code to modify the AutoScrollPosition of the right panel in comboBox1_MouseWheel
The position of scrollbar is well changed, but the event is still catched by the combobox, and the liste in the combobox is still scrolled.
Can we cancel the event for the combobox
 
C

Claes Bergefall

Inherit ComboBox, override it's OnMouseWheel and don't call the base class
Don't forget to move your code from your event handler to the override
(since events will no longer be raised)

/claes

Vincent said:
I have a window vertically splitted in two parts : on the left a panel
containing controls (including a combobox),
and on the right a panel with scrollbars to display an image.
I wish that MouseWheel events act on the scrollbars to position the image.
but MouseWheel events are send to the combobox.
I add a MouseEventHandler to the combobox,
comboBox1.MouseWheel += new MouseEventHandler(comboBox1_MouseWheel);
and add the code to modify the AutoScrollPosition of the right panel in comboBox1_MouseWheel.
The position of scrollbar is well changed, but the event is still catched
by the combobox, and the liste in the combobox is still scrolled.
 
G

Guest

I create a sub class Like this
public class ComboNoWheel: System.Windows.Forms.ComboBo

public ComboNoWheel() : base(



protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e

// TODO : ajoutez l'implémentation de ComboNoWheel.OnMouseWhee
// base.OnMouseWheel (e)
// en fait retirer l'implémentation de bas
int a = 1
a += 1; // some code to put a break poin


I change the class of the control, and the new ComboNoWheel continues to change its selection when the mouse wheel moves
??
(I dont call the base.OnMouseWheel, it is in comments)
 
G

Guest

In the ComboBox, there is this définition :
protected override void WndProc ( System.Windows.Forms.Message m
Membre de System.Windows.Forms.ComboBo

Is it at this level that the MouseWheel action is processed
 
C

Claes Bergefall

OK. Try overriding WndProc instead

int WM_MOUSEWHEEL = 0x20A;
protected override void WndProc (System.Windows.Forms.Message m)
{
if m.Msg = WM_MOUSEWHEEL
// Do your stuff
else
base.WndProc(m);
}


/claes


Vincent said:
I create a sub class Like this :
public class ComboNoWheel: System.Windows.Forms.ComboBox
{
public ComboNoWheel() : base()
{
}

protected override void OnMouseWheel(System.Windows.Forms.MouseEventArgs e)
{
// TODO : ajoutez l'implémentation de ComboNoWheel.OnMouseWheel
// base.OnMouseWheel (e);
// en fait retirer l'implémentation de base
int a = 1;
a += 1; // some code to put a break point
}
}
I change the class of the control, and the new ComboNoWheel continues to
change its selection when the mouse wheel moves.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top