如果我的TextBox_Validating中有以下几行代码,TextBox上的tabstop将触发两次:
((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));
}
}发布于 2018-07-12 22:08:26
好了,我找到了一个变通办法..
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起作用了。
https://stackoverflow.com/questions/51307121
复制相似问题