Combobox下拉开关在mousehover C#winforms上 [英] Combobox dropdown open-close on mousehover C# winforms

查看:131
本文介绍了Combobox下拉开关在mousehover C#winforms上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当光标到达组合框时如何加载下拉列表并在光标离开组合框时关闭?



我尝试了什么: < br $>


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

推荐答案

试试这个,工作。



Try this, working.

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

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





想法来自 HobbyProggy [ ^ ],来自评论。


这篇关于Combobox下拉开关在mousehover C#winforms上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆