我正在尝试使用Tab键完成焦点时选择所有文本。但我无法找到合适的解决方案。现在我正在使用 GotFocusEvent 但是现在当我用鼠标点击它时会引发事件。
我现在使用的代码是:
EventManager.RegisterClassHandler(typeof(System.Windows.Controls.TextBox), System.Windows.Controls.TextBox.GotKeyboardFocusEvent, new RoutedEventHandler(SelectAllText));
void SelectAllText(object sender, RoutedEventArgs e)
{
var textBox = sender as System.Windows.Controls.TextBox;
if (textBox != null)
if (!textBox.IsReadOnly)
textBox.SelectAll();
}
答案 0 :(得分:4)
参考这个答案
Textbox SelectAll on tab but not mouse click
您拥有的内容可以修改为......
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class, args);
}
}
您还应该注意有关在@RestController
public class GreetingsController {
@Autowired
private SomeService svc;
@RequestMapping("/greeting")
public String greeting() {
System.out.println(svc.sayHello());
return svc.sayHello();
}
}
答案 1 :(得分:0)
使用MouseButtonState
,如下所示:
void SelectAllText(object sender, RoutedEventArgs e)
{
if (Mouse.LeftButton == MouseButtonState.Released)
{
var textBox = sender as System.Windows.Controls.TextBox;
if (textBox != null)
if (!textBox.IsReadOnly)
textBox.SelectAll();
}
}