过程C#的WinForms按钮按键? [英] Process c# winforms button as keystroke?

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

问题描述

我要按下时,使上一个按钮,组合键<大骨节病>控制 + <大骨节病> + 被按下,另一个其中<大骨节病>控制 + <大骨节病> - 被按下。我如何才能做到这一点。


解决方案

下面是你想要的一个可能的解决方案:

  //按钮创建
键则myButton =新按钮();
myButton.Click + = myButton_Click;



然后在事件 myButton_Click();

 无效myBu​​tton_Click(对象发件人,EventArgs五)
{
SendKeys.Send(^({ ADD}))
}

然后,您可以做类似的 - 键,选中的这里的关键符号使用



修改



另一个变化是这样做,而不是:

 无效myBu​​tton_Click(对象发件人,EventArgs五)
{
SendKeys.Send(^({+}))
}



<块引用>

加号(+),插入符号(^),百分号(%),波形符(〜)以及括号()有特殊含义的SendKeys。要指定这些字符之一,大括号括起来({})。例如,要指定加号,请使用{+}




来源:



创建按钮点击事件C#



触发键盘按键事件而不按键盘从按键


I want to make a button on that when pressed, the key combination Ctrl + + is pressed and another where Ctrl + - is pressed. How can I achieve this?

解决方案

Here is a possible solution for what you want:

//Button creation
Button myButton= new Button();
myButton.Click += myButton_Click;

Then in the event myButton_Click();

void myButton_Click(object sender, EventArgs e)
{
    SendKeys.Send("^({ADD})")
}

You can then do similar for the - key, check here for the key symbols to use

EDIT

The other variation is to do this instead:

void myButton_Click(object sender, EventArgs e)
{
    SendKeys.Send("^({+})")
}

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}".

Sources:

Created Button Click Event c#

Trigger a keyboard key press event without pressing the key from keyboard

这篇关于过程C#的WinForms按钮按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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