在每个文本框的KeyDown事件中,判断按下的键是否为Tab键,如果是,则获取当前文本框的行和列,然后将下一个文本框的行和列设置为当前行和列加1,如果下一个文本框不存在,则将行加1,列设为1。最后将焦点设置到下一个文本框中。

private void Text_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Tab) { TextBox currentTextBox = (TextBox)sender; int row = Grid.GetRow(currentTextBox); int column = Grid.GetColumn(currentTextBox); column++; if (column > 11) { row++; column = 1; } UIElement nextElement = grid.Children .Cast() .FirstOrDefault(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == column); if (nextElement != null) { nextElement.Focus(); } }

C# 增加按tab键就下一个文本框 中文 private MaintenanceMetrics Closing += MaintenanceMetrics_Closing; gridRowDefinitionsAddnew RowDefinition Height = new GridLength70 ; g

原文地址: https://www.cveoy.top/t/topic/c0PL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录