[英]Can the AcceptButton property on a C# winform be changed from the Enter key to using Ctrl+Enter without using a TextBox?
I'm working on updates to a program I wrote a while ago (and thank you all for helping out with my previous question!), and I've run into a hiccup.我正在更新我不久前编写的程序(感谢大家帮助解决我之前的问题!),但我遇到了问题。 I'd like to make it so that my program will submit its data to the SharePoint list using CTRL+ENTER without needing a TextBox.
我想这样做,以便我的程序使用 CTRL+ENTER 将其数据提交到 SharePoint 列表,而无需 TextBox。
I've scoured Google Searches for hours and haven't found anything that really gives me the functionality I want.我已经在 Google 搜索上搜索了几个小时,但没有找到任何能够真正提供我想要的功能的东西。 I'm not married to using the AcceptButton feature on the WinForm, so any suggestions to make this work are welcome.
我不习惯在 WinForm 上使用 AcceptButton 功能,因此欢迎提出任何使这项工作起作用的建议。
I've tried various variations of this code to make it cooperate, but it didn't work out at all.我已经尝试了此代码的各种变体以使其协作,但根本没有奏效。
if (e.SuppressKeyPress = (e.KeyData == (Keys.Control | Keys.Enter)))
{
SubmitBtn.Focus();
SubmitBtn.PerformClick();
}
I just need the program to click a button once CTRL+ENTER is pressed.我只需要程序在按下 CTRL+ENTER 后单击一个按钮。 The button itself does the rest of the work.
按钮本身完成其余的工作。
I actually did manage to get this to work after a lot of trial, error, and splicing together samples from a vast number of different forums.经过大量的试验、错误和将来自大量不同论坛的样本拼接在一起,我确实设法使这个工作正常进行。 Here's what ended up working for me.
这就是最终对我有用的东西。 If there are any edits that would make it more streamlined, please feel free to let me know.
如果有任何编辑可以使其更加精简,请随时告诉我。
private void SubmitShortcut(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter && e.Control)
{
e.Handled = true;
SubmitBtn_Click(sender, e);
}
else if (e.KeyCode != Keys.Enter && e.Control)
{
e.Handled = false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.