如何在C#中输入按钮? [英] How to make enter button in C#?

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

问题描述

我想在c#windows窗体中创建一个输入按钮,就像键盘输入按钮一样。



我尝试过:



if(lastFocused!= null)

{

SendKeys.Send({ENTER} );

lastFocused.Text = lastFocused.Text;

}

I want to make an enter button in c# windows form that work like a key board enter button.

What I have tried:

if (lastFocused != null)
{
SendKeys.Send("{ENTER}");
lastFocused.Text = lastFocused.Text;
}

推荐答案

如果你的意思是关闭表单并将DialogResult.OK返回到调用代码,然后它很简单。

在表单上放下按钮。

转到按钮的属性窗格。

将DialogResult属性设置为OK

转到包含表单的属性窗格。

将AcceptButton属性设置为按钮。



完成。

现在,当您按下键盘上的ENTER或按钮本身时,表格将关闭。
If you mean "closes the form and returns DialogResult.OK to the calling code", then it's simple.
Drop your button on the form.
Go to the Properties Pane for the button.
Set the DialogResult property to OK
Go to the Properties Pane for the containing form.
Set the AcceptButton property to the button.

Done.
Now, when you press ENTER on your keyboard, or the button itself, the form will close.


只需前往酒店并在接受按钮中选择button1



就是这样
Just go to the property and in that Accept button - choose button1

that's it


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

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