首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证不工作中的C# TabStop

验证不工作中的C# TabStop
EN

Stack Overflow用户
提问于 2018-07-12 21:36:20
回答 1查看 39关注 0票数 1

如果我的TextBox_Validating中有以下几行代码,TextBox上的tabstop将触发两次:

代码语言:javascript
复制
((TextBox)sender).AutoCompleteCustomSource.AddRange(new string[]
{
    ((TextBox)sender).Text,
});

但是,如果移除Tabstop上方的线条工作正常,并且只触发一次?

这是整个函数:

代码语言:javascript
复制
 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));
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2018-07-12 22:08:26

好了,我找到了一个变通办法..

代码语言:javascript
复制
        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时,我手动将焦点设置到下一个控件。所以我的tabstop起作用了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51307121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档