快捷键未在表单中正常工作

时间:2011-10-08 05:47:05

标签: vb.net

使用VB.Net(Windows应用程序)

在表格,文本框,组合框等中......

  ->  When i open the windows form, if i press ctrl + Enter, then pop windows is opening 
  ->  if i enter any data's in the text box, then i press ctrl + Enter, then pop windows is not opening

代码

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.KeyPreview = True
End Sub

Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        If e.KeyCode = Keys.Control + e.KeyCode = Keys.Enter Then
            frmList.sFormID = 51
            frmList.Show()
        End If

End Sub

当表单加载时,ctrl + Enter快捷键正常工作,一旦我输入或选择表单中的任何数据,则ctrl + Enter快捷键不起作用(不显示弹出窗口)

我的代码有什么问题。如何解决这个问题...

需要Vb.net代码帮助

1 个答案:

答案 0 :(得分:1)

设置Form.KeyPreview=True并使用Modifiers标记。

Private Sub form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  If e.Modifiers = Keys.Control And e.KeyCode = Keys.Enter Then
     frmList.sFormID = 51
     frmList.Show()
  End If
End Sub