c# - 同时从多个文本框中选择文本

标签 c# textbox

我有 10 个文本框,我需要从每个文本框中选择文本。 问题是我无法从多个文本框中选择文本。 我的代码有这个问题的解决方案吗?

 private void Form1_Load(object sender, EventArgs e)
    {
        createTextBoxes(10);

        ((TextBox)textBoxes[0]).Select(1, 4);
        ((TextBox)textBoxes[1]).Select(1, 4); // <- it will not select text 
        ((TextBox)textBoxes[2]).Select(1, 4); // same here
    }
    Control[] textBoxes;
    private void createTextBoxes(int cnt)
    {
        textBoxes = new Control[cnt];
        for (int i = 0; i < cnt; i++)
        {
            TextBox tb = new TextBox();
            tb.Name = i.ToString();
            tb.Location = new Point(5, 5 + 14 * i);
            tb.Size = new Size(600, 20);
            tb.BorderStyle = BorderStyle.None;
            tb.Text = "sample text" + i.ToString();
            textBoxes[i] = tb;
            this.Controls.Add(tb);
        }
    }

最佳答案

将文本框的 HideSelection 属性设置为 false。他们在失去焦点后仍会保持选择。

关于c# - 同时从多个文本框中选择文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/868976/

相关文章:

c# - List<MyClass> 作为 DropDownList 的数据源?

c# - "Must be already floating point"将音频文件转换为 wav 文件时

c# - 来自 textBox 的值没有被插入到数据库中

wpf - WPF中的文本框键入事件

c# - 使用 C# 4.0 避免过载 hell

c# - 如何在 C# 中实现 Excel Solver 功能?

php - php中如何保存文本区域的数据

javascript - 是否有用于淡化文本框提示的 jQuery 插件?

c# - 使用 MS Access 作为 .NET 应用程序后端

javascript - 如何将下拉列表更改为 jQuery 中选择的文本框?