C#点击自动填充文本框延迟的建议项目 [英] C# Click suggestion item on autocomplete textbox delay

查看:98
本文介绍了C#点击自动填充文本框延迟的建议项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用建议文本框自动完成模式并做一些事件(例如:在textbox_textchanged上更改文本框前景色。当
我使用键盘上/下箭头键改变选择时,它正在快速工作,完全没有延迟。但是当我使用click来选择一些建议项目时,延迟大约1秒直到textbox_textchanged事件开始执行。

推荐答案

嗨乔丹,

是的,似乎我可以 在Winform项目的测试中重现您的问题,我们知道,显示了自动完成列表在textBox下将根据键入的文本自动过滤项目。我担心
的根本原因是问题是自动完成列表是基于键入的文本所以需要经常刷新。这将导致UI响应非常缓慢并导致许多意外问题。

Yes it seems that, I can also reproduce your issue in my test with Winform project, as we know, the auto complete list shown under the textBox will filter the items automatically based on the typed text. I'm afraid the root cause of the issue is that the auto complete list is based on the typed text so it needs to be refreshed very frequently. This will cause the UI response very slowly and lead to so many unexpected issues.

我不确定是否存在 在Winform中解决它的一些好的解决方案,但是作为
替代解决方案,您可以尝试在Winform中托管WPF控件:

I'm not sure if there aresome good solutions to solve it in Winform, but as an alternative solution, you can try to host a WPF control in Winform:

步骤1:将ElementHost拖到窗体中:

第2步:添加引用:

第3步:在表格加载事件中:

    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        AutoCompleteBox AtClBox;
        private void Form3_Load(object sender, EventArgs e)
        {
            AtClBox = new AutoCompleteBox();
            AtClBox.TextChanged += AtClBox_TextChanged;
            AtClBox.FontSize = 16;

            AtClBox.FontFamily = new System.Windows.Media.FontFamily("Segoe UI");
            elementHost1.Child = AtClBox;

            List<string> cityList = new List<string>(){
                                            "city1",
                                            "city2",
                                            "city3",
                                            "city4",
                                            "city5",
                                            "city6",
                                            "city7",
                                            "city8",
                                            "city9" };

            AtClBox.MinimumPopulateDelay = 100;
            AtClBox.MinimumPrefixLength = 1;
            AtClBox.ItemsSource = cityList;
        }

        private void AtClBox_TextChanged(object sender, System.Windows.RoutedEventArgs e)
        {
            AtClBox.Background = System.Windows.Media.Brushes.Aqua;
        }
    }

问候,

Frankie


这篇关于C#点击自动填充文本框延迟的建议项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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