Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
190
Cannot disable mouse wheel in UltraComboEditor.
posted

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;
        }

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    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;           

            }

Children