【问题标题】:C# TabStop in Validating not working验证中的 C# TabStop 不起作用
【发布时间】:2018-12-20 18:32:05
【问题描述】:

如果我的 TextBox_Validating 中有这些行,TextBox 上的制表位将被触发两次:

((TextBox)sender).AutoCompleteCustomSource.AddRange(new string[]
{
    ((TextBox)sender).Text,
});

但是如果删除 Tabstop 上方的行可以正常工作并且只触发一次?

这是整个函数:

 private void TextBox_Validating(object sender, EventArgs e)
    {
        if (!((TextBox)sender).AutoCompleteCustomSource.Contains(((TextBox)sender).Text) && ((TextBox)sender).TextLength > 0)
        {
            ((TextBox)sender).AutoCompleteCustomSource.AddRange(new string[]
            {
               ((TextBox)sender).Text,
            });

            SaveHistoryTextBox(((TextBox)sender));
        }
    }

【问题讨论】:

  • 这是您的实际代码还是缺少什​​么?
  • 我发现“AutoCompleteCustomSource.AddRange”不断将焦点返回到 TextBox,因此无法使用该选项卡。但为什么呢?

标签: c# autocomplete textbox tabstop validating-event


【解决方案1】:

好的,我找到了解决方法..

        private void TextBox_Validating(object sender, EventArgs e)
    {
        if (!((TextBox)sender).AutoCompleteCustomSource.Contains(((TextBox)sender).Text) && ((TextBox)sender).TextLength > 0)
        {
            ((TextBox)sender).AutoCompleteCustomSource.AddRange(new string[]
            {
               ((TextBox)sender).Text,
            });

            SaveHistoryTextBox(((TextBox)sender));

            Control p;
            p = ((TextBox)sender).Parent;
            p.SelectNextControl(ActiveControl, true, true, true, true);
        }
    }

使用 p.SelectNextControl 我手动将焦点设置到下一个控件。所以我的制表位正在工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多