【问题标题】:On lable focus enter press to raise event在标签焦点上输入按下以引发事件
【发布时间】:2013-08-07 22:52:21
【问题描述】:

当我的标签有焦点并且有人点击“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”做一些事情,但我不确定它会是什么样子。感谢您的帮助!

【问题讨论】:

    标签: vb.net events focus label enter


    【解决方案1】:

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

    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
    

    注意:有几个key-type事件,例如KeyPressKeyDownKeyUp

    【讨论】:

    • 我不会像现在这样在 sub 中的任何地方传递 e。那我应该在 form.load 事件上这样做吗?或者创建一个新的子来处理我的:AssignOwnersLabel.Click 事件?
    • 啊,我的错,我已更新我的答案以显示生成 e 事件参数的事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多