【问题标题】:C# How to call KeyUp event in button?C#如何在按钮中调用KeyUp事件?
【发布时间】:2017-12-28 23:37:45
【问题描述】:

我有这段代码,我只能通过 KeyPress 执行,我想通过按钮调用事件,这样它就会像我按下键盘上的实际键一样运行。这是我的代码:

private void dataGridView1_KeyUp(object sender, KeyEventArgs e) {
    if (e.KeyCode == Keys.Down) { 
        dataGridView1_CellDoubleClick(this.dataGridView1, _
                                      new DataGridViewCellEventArgs(this.dataGridView1.CurrentCell.ColumnIndex, _
                                                                    this.dataGridView1.CurrentRow.Index));
    } else if (e.KeyCode == Keys.Up) {
        dataGridView1_CellDoubleClick(this.dataGridView1, _
                                      new DataGridViewCellEventArgs(this.dataGridView1.CurrentCell.ColumnIndex, _
                                                                    this.dataGridView1.CurrentRow.Index));
    }
}

【问题讨论】:

  • 数据网格中是否存在按钮??

标签: c# events button datagridview keyup


【解决方案1】:

为什么不直接在按钮的点击处理程序

上调用事件
void btn_Click(object sender,EventArgs e)
{
  dataGridView1_KeyUp(dataGridView1,new KeyEventArgs(Keys.Down));
}

对于任何函数调用或处理程序调用都是如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2014-06-28
    • 2014-06-05
    相关资源
    最近更新 更多