表单中的KeyDown事件 [英] KeyDown event in a Form

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

问题描述

我需要将 Ctrl + Z 组合键与自定义表单操作(撤消)关联.

I need to associate Ctrl+Z key combination to a custom form action (Undo).

我处理 Me.KeyDown 事件,但是每次按下按键时都不会收到.也许这取决于我目前具有某种形式的活动控制.

I handle Me.KeyDown event, but don't receive it each time I press keys. Perhaps it depends of what currently active control in a form I have.

这篇文章中阅读我需要

  Private Sub MyForm_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    e.Handled = True
  End Sub

但是,即使是这个事件,我也没有收到,但是当集中控制某些控件而不是其他控件时.

but even this event I don't receive but when having some controls focused, but not others.

  • 除此之外,对于文本框,我无法再修改文本;
  • 对于 TextBoxes ,还有(Windows?)撤消-重做默认机制,它应该也可以工作.
  • 我该怎么做才能始终在表单上收到 KeyDown 事件?
  • More that than, for the TextBoxes I can't modify the text anymore;
  • More that than, for the TextBoxes there is a (Windows?) Undo-Redo default mechanism, that should work too.
  • What should I do to always recieve the KeyDown event on the form?

推荐答案

您可以覆盖 ProcessCmdKey 来处理表单级别的按键.

You can override ProcessCmdKey to handle key presses on the form level.

有关更多详细信息和示例,请参阅此问题: Windows Forms .NET中的热键(非全局)

See this question for more details and examples: Hotkey (not global) in Windows Forms .NET

这篇关于表单中的KeyDown事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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