【问题标题】:RichTextBox as output and TextBox as input on one form, how to select from output while maintaining focus on input?RichTextBox 作为输出,TextBox 作为输入在一个表单上,如何在保持对输入的关注的同时从输出中进行选择?
【发布时间】:2012-02-03 12:38:27
【问题描述】:

我有一个 RichTextBox 作为输出,TextBox 作为 WinForms 主窗体上的输入。我希望能够在用鼠标突出显示输出中的文本时将注意力集中在 TextBox 上。例如,这将允许我在输入中键入一些内容,同时用鼠标在输出中选择一些内容。

我在一个不一定基于 WinForms 的应用程序中看到了这一点,但它确实在 Windows 机器上运行。

如何使用 WinForms 做到这一点?

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    你可以尝试一下

        bool selecting;
    
        private void richTextBox1_SelectionChanged(object sender, EventArgs e)
        {
            selecting = true;
        }
    
        private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (selecting)
                textBox1.Focus();
            selecting = false;
        }
    

    这会在您完成从 RichTextBox 中的选择后立即重置 TextBox 上的焦点。然而问题是,一旦焦点恢复,选择就会被清除。

    【讨论】:

    • 在我所指的应用程序中,在输出窗口中单击鼠标,然后您可以选择文本,一直向右或向左拖动鼠标,而输入 TextBox 仍将占用键盘输入,不间断。会不会涉及线程?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多