如何在winform中允许带有TextBox的ctrl + a?

How can I allow ctrl+a with TextBox in winform?(如何在winform中允许带有TextBox的ctrl + a?)
本文介绍了如何在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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)