简体   繁体   English

C# winform 上的 AcceptButton 属性是否可以从 Enter 键更改为使用 Ctrl+Enter 而不使用 TextBox?

[英]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.

相关问题 使用C#StandardInput重定向时如何将Ctrl + Enter命令传递给Process - How to pass Ctrl+Enter command to Process when using C# StandardInput redirection 如何模拟ctrl+enter - How to simulate ctrl+enter 当使用C#在Windows窗体中按Enter键时,如何从动态文本框中提交和检索文本? - How to submit and retrieve text from dynamic textbox when Enter key is pressed in Windows forms using C#? 在WPF中处理文本框上的Enter事件时,如何接受Ctrl + Enter作为返回? - How to accept Ctrl+Enter as return while processing Enter event on a Textbox in WPF? 当用户在带有 AcceptsReturn = "True" 的 UWP 文本框中按 CTRL+ENTER 键时如何避免换行 - How to avoid newline when user presses CTRL+ENTER keys in a UWP TextBox with AcceptsReturn = "True" “ Enter”键在C#Winform数字猜测(Hangman)游戏中不起作用 - “Enter” key not working in C# Winform number guessing (Hangman) game C# WinForm KeyPress Enter 键在点击链接后不触发 - C# WinForm KeyPress Enter key not fire after link clicked 当文本框值更改为事件时,自动按下输入C# - auto press enter C# when textbox value changed as event TextBox没有监听在C#中按空格键之前输入密钥 - TextBox not listening Enter key before Space key is pressed in C# c#中的变量和文本框映射而不使用文本框更改事件 - variable and textbox mapping in c# without using textbox changed event
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM