为什么添加dgv,停止Form1_KeyDown事件? [英] Why does adding a dgv, stop a Form1_KeyDown event?

查看:111
本文介绍了为什么添加dgv,停止Form1_KeyDown事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何使用回车键。我的代码将有助于解释我的问题。

 私有  Sub  Form1_KeyDown(发件人作为 对象,e 作为 KeyEventArgs)句柄  MyBase  .KeyDown 
如果 e.Control AndAlso e.KeyCode = Keys.Enter 那么
MsgBox( 您按下Control键+ Enter键
e.Handled = False
结束 如果
结束 Sub



此代码按预期工作,但是当我添加DGV时控制到它不再有效的形式。如何在同一表格上使用DGV控件?



我的最终目标是使用Enter键启动或执行DGV_CellEndEdit事件。 div class =h2_lin>解决方案

它不起作用可能是因为DGV具有焦点,而不是形式。您可以将Forms KeyPreview属性设置为true,以便现有的事件处理程序代码可用,或者您可以创建自己的DGV控件版本并在自己的控件中处理其KeyDown事件。


I am trying to learn how I can use the enter key. My code will help explain my question.

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
        If e.Control AndAlso e.KeyCode = Keys.Enter Then
            MsgBox("You pressed the Control Key + Enter key")
            e.Handled = False
        End If
    End Sub


This code works as expected, however when I add a DGV control to the form it no longer works. How can I make it work with a DGV control on the same form?

My ultimate goal is to use the Enter key to either initiate or perform the DGV_CellEndEdit event.

解决方案

It doesn't work probably because the DGV has the focus, not the form. You can either set the Forms KeyPreview property to true where your existing event handler code will work or you can create your own version of the DGV control and handle its KeyDown event in your own control.


这篇关于为什么添加dgv,停止Form1_KeyDown事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆