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?
基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
