【发布时间】:2013-02-23 11:56:32
【问题描述】:
在我的 Visual Studio 2010 的 winforms 应用程序中,
我有一个按钮和两个组合框(combobox1,combobox2)。
我在按钮中添加了代码来清除第一个组合框(combobox1)中先前输入的数据并设置焦点。
在第一个组合框(combobox1)的 keyup 事件中,我检查了输入键,如果按下,焦点将移动到下一个组合框(combobox2)。
但我的问题是,当我按下按钮时(通过在焦点位于按钮上时按下回车键),焦点直接移动到最后一个(第二个)组合框(combobox2)。
combobox1 的 Keyup 事件会自动触发,尽管我只在按钮上输入了
我该如何解决这个问题?
下面是我的代码
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'code to perform database action
Me.ComboBox1.Focus()
End Sub
Private Sub ComboBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles ComboBox1.KeyUp
If e.KeyCode = Keys.Enter Then
If Me.ComboBox1.SelectedText = String.Empty Then
ComboBox2.Focus()
End If
End If
End Sub
更新
当我点击按钮时,问题不会出现 但是,当我在焦点位于按钮上时按 Enter 键,触发按钮单击事件时,就会出现问题。
【问题讨论】: