如何拦截WinForms应用程序捕获TAB键? [英] How to intercept capture TAB key in WinForms application?

查看:118
本文介绍了如何拦截WinForms应用程序捕获TAB键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉到的标签的在Windows键窗体应用程序,做一个自定义操作时,它是pressed。

I'm trying to capture the Tab key in a Windows Forms application and do a custom action when it is pressed.

我曾与几个列表视图和按钮的形式,我已经设置窗体的键preVIEW 的属性设置为true,当我preSS比卡任何其他键,我的KeyDown事件处理程序被调用。

I have a Form with several listViews and buttons, I've set the Form's KeyPreview property to true and when I press any other key than tab, my KeyDown event handler does get called.

但是,这不是真正的用的标签的关键 - 我没有收到WM_KEYDOWN消息,即使在WndProc中

But that's not true with the Tab key - I don't receive WM_KEYDOWN message even in WndProc.

我是否需要设置每个控件内部自己的状态 - 它的接受tab 的属性 - 假?必须有比这更优雅的方式。

Do I need to set each control inside my form - its TabStop property - to false? There must be a more elegant way than that.

感谢。

推荐答案

会的这个帮你?

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
  Dim keyPressed As Keys = CType(msg.WParam.ToInt32(), Keys)

  Select Case keyPressed
    Case Keys.Right msgbox("Right Arrow Key Caught")
    Case Keys.Left msgbox("LeftArrow Key Caught")
    Case Keys.Up msgbox("Up Arrow Key Caught")
    Case Keys.Down msgbox("Down Arrow Key Caught")
    Case Else Return MyBase.ProcessCmdKey(msg, keyData)
  End Select
End Function 

这篇关于如何拦截WinForms应用程序捕获TAB键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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