为什么设置 DroppedDown 时 ComboBox 隐藏光标? [英] Why ComboBox hides cursor when DroppedDown is set?

查看:20
本文介绍了为什么设置 DroppedDown 时 ComboBox 隐藏光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们创建 WinForms 应用程序(我在 Windows Vista 上运行 Visual Studio 2008,但似乎所描述的情况几乎发生在从 Win98 到 Vista 的任何地方,在本机或托管代码上).

Let's create WinForms Application (I have Visual Studio 2008 running on Windows Vista, but it seems that described situation takes place almost everywhere from Win98 to Vista, on native or managed code).

编写这样的代码:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class Form1 : Form
    {
        private readonly Button button1 = new Button();
        private readonly ComboBox comboBox1 = new ComboBox();
        private readonly TextBox textBox1 = new TextBox();

        public Form1() {
            SuspendLayout();
            textBox1.Location = new Point(21, 51);
            button1.Location = new Point(146, 49);
            button1.Text = "button1";
            button1.Click += button1_Click;
            comboBox1.Items.AddRange(new[] {"1", "2", "3", "4", "5", "6"});
            comboBox1.Location = new Point(21, 93);
            AcceptButton = button1;
            Controls.AddRange(new Control[] {textBox1, comboBox1, button1});
            Text = "Form1";
            ResumeLayout(false);
            PerformLayout();
        }

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

然后,运行应用程序.将鼠标光标放在表单上,​​不要再触摸鼠标了.开始在 TextBox 中输入内容 - 光标将因此隐藏.当您按下 Enter 键时 - 事件会引发并且 ComboBox 将被下拉.但是现在即使移动光标也不会出现!并且仅在您单击某处时出现.

Then, run app. Place mouse cursor on the form and don't touch mouse anymore. Start to type something in TextBox - cursor will hide because of it. When you press Enter key - event throws and ComboBox will be dropped down. But now cursor won't appear even if you move it! And appears only when you click somewhere.

那里我发现了关于这个的讨论问题.但是没有很好的解决方案...

There I've found discussion of this problem. But there's no good solution...

有什么想法吗?:)

推荐答案

我能够解决这样的问题:

I was able to work around the problem like this:

comboBox1.DroppedDown = true;
Cursor.Current = Cursors.Default;

这篇关于为什么设置 DroppedDown 时 ComboBox 隐藏光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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