Shift键按下事件 [英] shift key down event

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

问题描述

当我将按shftkey然后将button1.text更改为S时,请告诉

when i will press shftkey then button1.text changes to S how i will do this please tell

推荐答案

这不是太简单:取决于您所拥有的形式.您需要处理KeyDown和KeyUp事件,但可能必须为所有控件处理它们,以避免丢失事件.试试吧:
在您的窗体中放置一个文本框,处理Key Down事件.在处理程序中,检查KeyEventArgs.KeyCode以查看它是否为Keys.ShiftKey-如果是,则可以播放文本.

唯一的问题是,您可能必须在每个控件中单独捕获它:如果有一个可以处理键盘输入的控件,则整个form事件将无法获取代码.
It''s not too simple: it depends on what you have in your form. You need to handle the KeyDown and KeyUp events, but you will have to handle them for all controls, probably, to avoid missing events. Try it:
Put a Text box in your form, handle the Key Down event. In the handler, check the KeyEventArgs.KeyCode to see if it is Keys.ShiftKey - if it is, you can play with your text.

The only problem is that you will probably have to catch this independently in each control: The overall form event will not get the code if there is a control that can handle keyboard input.


Griff是对.方法如下:

Griff is right. Here is how:

public partial class MyForm : Form {
        
    public MyForm() {
        InitializeComponent();
        SetupShiftEvents(this);
    } //MyForm

    void SetupShiftEvents(Control parent) {
        parent.KeyDown += (sender, eventArgs) => {
            if (eventArgs.KeyCode == Keys.ShiftKey)
                this.buttonShift.Text = "Shift";
        };
        parent.KeyUp += (sender, eventArgs) => {
            if (eventArgs.KeyCode == Keys.ShiftKey)
                this.buttonShift.Text = "Normal";
        };
        foreach (Control child in parent.Controls)
            SetupShiftEvents(child);
    } //SetupShiftEvents

} //class MyForm



它可以正常工作,经过测试.你有主意.您可以在您的VB.NET中翻译它吗? :-)

—SA



It works, tested. You have the idea. Can you translate it in your VB.NET? :-)

—SA


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

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