闪烁的文本框

时间:2019-04-07 12:04:09

标签: c# winforms autocomplete textbox

由于某种原因,如果我要更改文本框的AutoCompleteCustomSource属性,它会消失一秒钟然后显示。我已经尝试过在另一个线程中执行此操作,但是它对任何想法似乎都没有帮助?

没有外部线程的代码:

private void nickName_TextChanged(object sender, EventArgs e)
        {
            //Thread updateAC = new Thread(updateAutoComplete);
            //updateAC.Start();
            AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
            collection.AddRange(db.getUsersByLetters(nickName.Text).ToArray());
            nickName.AutoCompleteCustomSource = collection;
            ((mainForm)Parent).currentNick = nickName.Text;    
            error.Visible = false;
        }

带外螺纹的代码:

        private void nickName_TextChanged(object sender, EventArgs e)
        {
            Thread updateAC = new Thread(updateAutoComplete);
            updateAC.Start();
            ((mainForm)Parent).currentNick = nickName.Text;    
            error.Visible = false;
        }

        public delegate void InvokeDelegate();
        private void updateAutoComplete()
        {
            AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
            collection.AddRange(db.getUsersByLetters(nickName.Text).ToArray());
            nickName.Invoke(new InvokeDelegate(() => { nickName.AutoCompleteCustomSource = collection;}));
        }

结果: enter image description here

0 个答案:

没有答案