Ricardo·M·Smile 2015-05-27 12:22 采纳率: 75%
浏览 3522
已采纳

c# winform中如何控制焦点。新人求教。

如何实现光标在文本框的,数据库的表格在按上下键时可以移动。就是下面这种情况。
图片说明

  • 写回答

5条回答 默认 最新

  • 全栈极简 领域专家: 后端开发技术领域 2015-05-27 14:47
    关注
     private void textBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyData == Keys.Down)
                {
                    this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index + 1 > this.dataGridView1.Rows.Count ? this.dataGridView1.Rows.Count - 1 : this.dataGridView1.CurrentRow.Index + 1].Selected = true;
                }
    
                if (e.KeyData == Keys.Up)
                {
                    this.dataGridView1.Rows[this.dataGridView1.CurrentRow.Index - 1 < 0 ? 0 : this.dataGridView1.CurrentRow.Index - 1].Selected = true;
                }
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?