我遇到了类似的问题 - 我创建了一个Windows窗体应用程序,它基本上根据输入到ToolStripTextBox中的代码从SQL服务器查找数据。单击按钮时效果很好但是我想在输入后添加点击输入的功能,并将结果通过。
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DataSet.Table' table. You can move, or remove it, as needed.
Me.TableTableAdapter.Fill(Me.DataSet.Table)
End Sub
Private Sub FillBySearchToolStripButton_Click(sender As Object, e As EventArgs) Handles FillBySearchToolStripButton.Click
Try
Me.TableTableAdapter.FillBySearch(Me.DataSet.Table, TYPEToolStripTextBox.Text)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
作为我是新手的应用。
答案 0 :(得分:0)
只需使用KeyDown事件:
Private Sub ToolStripTextBox1_KeyDown(sender As Object, e As KeyEventArgs) _
Handles ToolStripTextBox1.KeyDown
If e.KeyCode = Keys.Enter Then
'run your code
End If
End Sub
“运行你的代码”块只能调用click事件:
FillBySearchToolStripButton.PerformClick()