I want to disable mouse wheel in UltraComboEditor. In other words, I don't want user to select the item by mouse wheel, they can just select item from drop down list. I've tried many ways and all failed. But MS comboBox can handle everything as I want.
Then I made an experiment between MS comboBox and UltraComboEditor. I find that UltraComboEditor can not handle mouse wheel event while MS comboBox can. I tried 3 ways to debug whether this control can capture mouse wheel event. Blow is the 3 ways of my experiment. I set several breakponts to ensure combobox can handle mouse wheel event. MS combo can enter all the breakponts but UltraCombo can't. Anyone can help me?
const int WM_MOUSEWHEEL = 0x020A;
protected override void WndProc(ref Message m) { //stop scroll if (m.Msg == WM_MOUSEWHEEL) { //but force next item int delta; if ((int)m.WParam > 0) { //up delta = 1; } else { //down delta = -1; } this.OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta));
return; }
base.WndProc(ref m); }
protected override void OnMouseWheel(MouseEventArgs e) { base.OnMouseWheel(e); }
public Form1() { this.testUltraCmb1.MouseWheel += new MouseEventHandler(testUltraCmb1_MouseWheel); }
public void testUltraCmb1_MouseWheel(object sender, MouseEventArgs e) { HandledMouseEventArgs handledArgs = e as HandledMouseEventArgs; if (handledArgs != null) handledArgs.Handled = true; }
Hi,
The reason this doesn't work is that when the UltraComboEditor goes into edit mode, it displays a TextBox control over the edit area. It is this TextBox which is handling the MouseWheel message. So you need to handle the event on the TextBox.
private void Form1_Load(object sender, EventArgs e) { this.ultraComboEditor1.ControlAdded += new ControlEventHandler(ultraComboEditor1_ControlAdded); this.ultraComboEditor1.ControlRemoved += new ControlEventHandler(ultraComboEditor1_ControlRemoved); } void ultraComboEditor1_ControlRemoved(object sender, ControlEventArgs e) { TextBox textBox = e.Control as TextBox; if (textBox != null) textBox.MouseWheel -= new MouseEventHandler(ultraComboEditor1_MouseWheel); } void ultraComboEditor1_ControlAdded(object sender, ControlEventArgs e) { TextBox textBox = e.Control as TextBox; if (textBox != null) textBox.MouseWheel += new MouseEventHandler(ultraComboEditor1_MouseWheel); } void ultraComboEditor1_MouseWheel(object sender, MouseEventArgs e) { HandledMouseEventArgs handledArgs = e as HandledMouseEventArgs; if (handledArgs != null) handledArgs.Handled = true;
}
Thank you for your quick reply, Mike.
I have applied your code and I really can capture the mouse wheel event. But I still cannot forbid the Combo from change value by mouse wheel. If I set breakpoint both in MS comboBox's MouseWheel event and Ultra comboBox's MouseWheel event, then if I wheel mouse's middle button, MS comboBox will enter the breakpoint first and its text will not be changed, Ultra comboBox will change its text first then enter the breakpont. So it still not work as what I expected...