在标签焦点上输入按钮以提升事件

时间:2013-08-06 19:10:05

标签: vb.net events focus label enter

当我的标签有焦点且有人点击“回车”时,我正试图让这个子执行。这是我到目前为止的代码......

Private Sub AssignOwnersLabel_Click() Handles AssignOwnersLabel.Click
    Dim repository As OwnerRepositorySvc.OwnerRepositoryClient = Nothing

    For Each programRow As DataGridViewRow In ProgramOwnerFill.SelectedRows
        programRow.Cells(0).Value = AssignOwnersTXTBox.Text
    Next

    repository = OpenRepository()
    repository.SaveOwners(_ds)
    _ds.AcceptChanges()
    CloseRepository(repository)

    Dim dataview As DataView = _ds.ProgramOwners.DefaultView

    dataview.Sort = _ds.ProgramOwners.EmployeeIDColumn.ColumnName
    Me.ProgramOwnersBindingSource.DataSource = dataview

End Sub

我认为要让它工作,我需要用“keychar”做一些事情,但我不确定那会是什么样子。谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

要确定用户是否按下了回车键,请执行以下操作:

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    If e.KeyCode = Keys.Enter Then
        ' Put logic here for when the user pressed enter
    End if
End Sub

注意:有几种关键类型的事件,例如KeyPressKeyDownKeyUp