WinForms:如何防止文本框处理alt键并失去焦点? [英] WinForms: How to prevent textbox from handling alt key and losing focus?

查看:205
本文介绍了WinForms:如何防止文本框处理alt键并失去焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个文本框,用于捕获首选项配置的键盘快捷键.我使用低级的键盘挂钩来捕获按键,并防止它们采取操作,例如Windows键,但Alt键仍然会通过,并使我的文本框失去焦点.

I have this textbox I use to capture keyboard shortcuts for a preferences config. I use a low-level keyboard hook to capture keys and also prevent them from taking action, e.g. the Windows key, but the Alt key still comes through and makes my textbox lose focus.

如何阻止Alt键,使焦点保持不变?

How can I block the Alt key, so the focus is kept unaltered at my textbox?

推荐答案

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Alt)
    {
        e.Handled = true;
    }
}

这篇关于WinForms:如何防止文本框处理alt键并失去焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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