我怎样才能让CTRL

我怎样才能让CTRL

本文介绍了我怎样才能让CTRL + A在文本框的WinForm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要问的问题已经问过(甚至回答)位置:

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 我只听到金光闪闪类似,你听到的,如果你试图从一个空的文本框擦除文字金光闪闪(您的浏览器地址栏中尝试)。

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 应设置为真正。但是如果你的 TextBox.Multiline 已启用然后按Ctrl + A将无法正常工作(适用的)。使用的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.

这篇关于我怎样才能让CTRL + A在文本框的WinForm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:05