Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Load dropdown list while cursor reaches the combobox and close while cursor leaves the combobox?

What I have tried:

private void comboBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!comboBox1.ClientRectangle.Contains(e.Location))
                comboBox1.Capture = false;
            else if (comboBox1.Capture == false)
            {
                comboBox1.DroppedDown = true;
                //timer1.Interval = 1000;
                timer1.Start();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Point MP = new Point(Cursor.Position.X - this.Location.X, Cursor.Position.Y - this.Location.Y);
            Size DDS = new Size(comboBox1.DropDownWidth, comboBox1.DropDownHeight + comboBox1.Height);
            Rectangle DDR = new Rectangle(comboBox1.Left, comboBox1.Top, comboBox1.DropDownWidth, comboBox1.DropDownHeight * 2 + comboBox1.Height-20);
           

            if (!DDR.Contains(MP))
            {
                comboBox1.DroppedDown = false;
                timer1.Stop();
            }

            label1.Text = MP.ToString();
            label2.Text = DDR.ToString();
            label3.Text = comboBox1.Location.ToString() + "\n" + comboBox1.Size.ToString() ;
        }
Posted
Updated 28-Apr-16 2:54am
v3
Comments
HobbyProggy 28-Apr-16 5:52am    
Instead of the MouseMove you should use the MouseHover and there you just set the combobox on DroppedDown = true;

Then your combobox opens properly.
VR Karthikeyan 28-Apr-16 6:16am    
Add you comment as answer.
HobbyProggy 28-Apr-16 7:44am    
It's not complete though.

1 solution

Try this, working.

C#
private void comboBox1_MouseLeave(object sender, EventArgs e)
      {
          comboBox1.DroppedDown = false;
      }

      private void comboBox1_MouseMove(object sender, MouseEventArgs e)
      {
          comboBox1.DroppedDown = true;
      }


Idea from HobbyProggy [^], from the comments.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900