如何分配在Windows窗体快捷键(像按Ctrl + F)到一个文本框? [英] How to assign a shortcut key (something like Ctrl+F) to a text box in Windows Forms?

查看:128
本文介绍了如何分配在Windows窗体快捷键(像按Ctrl + F)到一个文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用C#的工具。这是一个Windows应用程序。我有一个表格上的一个文本框,我要分配焦点设置到文本框,当用户按下<大骨节病>控制 + <大骨节病>˚F或<大骨节病>控制 + <大骨节病>取值

I am building a tool using C#. It's a Windows application. I have one text box on a form, and I want to assign focus to that text box when the user presses Ctrl + F or Ctrl + S.

我如何做到这一点?

推荐答案

的KeyDown 事件和地点的,如果它的语句来检查被按什么键。

Capture the KeyDown event and place an if statement in it to check what keys were pressed.

private void form_KeyDown(object sender, KeyEventArgs e)
{
    if ((e.Control && e.KeyCode == Keys.F) || (e.Control && e.KeyCode == Keys.S)) {
        txtSearch.Focus();
    }
}

这篇关于如何分配在Windows窗体快捷键(像按Ctrl + F)到一个文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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