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

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

问题描述

让我们创建WinForms应用程序(我有Visual Studio 2008运行在Windows Vista上,但似乎描述的情况几乎发生在从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).

使用System编写这样的代码:

Write such 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键 - 事件throws和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...

任何想法? :)

推荐答案

我能够解决这个问题:

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

如果您遇到这个问题,我建议您投票相关的Microsoft错误报告。也许有一天他们会解决这个问题!

If you get hit by this issue as I did, I recommend voting up the related Microsoft bug report. Maybe someday they'll fix it!

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

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