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

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

本文介绍了如何在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);
    }
}

文本框出现,我可以在上面写字,我可以在上面剪切、复制和粘贴文本,没有任何问题.但是,当我尝试按 + 时,我只会听到类似于您尝试从空文本框中删除文本时听到的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 + 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 已启用,那么 + 将不起作用(参见 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 + will not work (see MSDN documentation). Using RichTextBox instead will get around the problem.

这篇关于如何在winform中允许带有TextBox的ctrl + a?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:15