文本框Keydown事件没有提升 [英] Text box Keydown event is not raising

查看:69
本文介绍了文本框Keydown事件没有提升的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我用MD快捷键在MDI中创建了一个菜单,同时我在某种形式的文本框按键事件中使用F1键。问题是当我在那个表格中点击F1时,文本框按键事件没有提升,因为它正在提升菜单项点击事件。我如何解决这个问题。



帮助我..

Hi all,

I created a menu in MDI with F1 shortcut and at the same time i am using F1 key in textbox key down event in some form.Issue is when i hit F1 in that form text box key down event is not raising where as it''s raising menu item click event.How can i resolve this issue.

Help me out..

推荐答案

由于F1快捷方式已经分配给主MDI表单中的菜单项,因此您不能再在其MDI中使用它儿童表格。



但是,您可以进行一些简单的设置更改以使其正常工作。



我假设您希望F1在主要MDI表单聚焦时执行不同的操作,而在MDI子项聚焦时则执行另一个不同的操作。如果是这样,那么您可以执行以下操作。



首先在主MDI表单中,打开子表单时,删除F1快捷键



Since the F1 shortcut has already been assigned to a menu item in the main MDI form, you cannot use it anymore in its MDI children form.

You can however do some simple settings change to make it work.

I assume you want the F1 do different action while the main MDI form is focused and another different action when the MDI children is focused. If that is so then you can do the following.

First at main MDI form, when opening the children form, remove the F1 shortcut key

Private Sub TestToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TestToolStripMenuItem.Click
        TestToolStripMenuItem.ShortcutKeys = Keys.None
        Dim f As New Form2
        f.MdiParent = Me
        f.Show()
    End Sub





然后当那个孩子n表格关闭,只需分配快捷键





Then when that children form closes, just assign the shortcut key back

Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
       TryCast(Me.MdiParent, MDIForm).TestToolStripMenuItem.ShortcutKeys = Keys.F1
   End Sub

   Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
       If e.KeyCode = Keys.F1 Then
           'Do stuff
       End If
   End Sub


这篇关于文本框Keydown事件没有提升的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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