How can I allow ctrl+a with TextBox in winform?(如何在winform中允许带有TextBox的ctrl + a?)
问题描述
我在这里问已经问过(甚至回答过)的问题:为什么有些文本框不接受 Control + A 快捷键默认全选
I'm asking the question already asked (and even answered) here: Why are some textboxes not accepting Control + A shortcut to select all by default
但是这个答案对我不起作用.我有这个代码:
But that answer doesn't work for me. I have this code:
public class LoginForm : Form
{
private TextBox tbUsername;
public LoginForm()
{
tbUsername = new TextBox();
tbUsername.ShortcutsEnabled = true;
tbUsername.Multiline = false;
Controls.Add(tbUsername);
}
}
文本框出现,我可以在上面写字,我可以在上面剪切、复制和粘贴文本,没有任何问题.但是,当我尝试按 Ctrl+A 时,我只会听到类似于您尝试从空文本框中删除文本时听到的bling"(尝试一下)使用浏览器的地址栏).
The textbox shows up, I can write on it, I can cut, copy and paste text on it without any problems. But when I try to press Ctrl+A I only hear a "bling" similar to the bling that you hear if you try to erase text from an empty textbox (try it with your browser's address bar).
推荐答案
如其他答案所示,应该调用 Application.EnableVisualStyles().此外,TextBox.ShortcutsEnabled 应设置为 true.但是如果您的 TextBox.Multiline 已启用,那么 Ctrl+A 将不起作用(参见 MSDN 文档).使用 RichTextBox 可以解决这个问题.
Like other answers indicate, Application.EnableVisualStyles() should be called. Also the TextBox.ShortcutsEnabled should be set to true. But if your TextBox.Multiline is enabled then Ctrl+A will not work (see MSDN documentation). Using RichTextBox instead will get around the problem.
这篇关于如何在winform中允许带有TextBox的ctrl + a?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在winform中允许带有TextBox的ctrl + a?
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 使用 rss + c# 2022-01-01
