简体   繁体   English

将选定的文本从RichTextBox传输到TextBox

[英]Transport selected text from RichTextBox to TextBox

I'm trying to make a windows form application. 我正在尝试制作Windows窗体应用程序。

When I select some numbers (by using the mouse) in my richTextBox I need to transport that selected number into my textBox by clicking a button. 当我在richTextBox中选择一些数字(通过使用鼠标)时,我需要通过单击按钮将该选定的数字传输到我的textBox中。

What code should I write in this button to make it work properly? 我应该在此按钮中编写什么代码才能使其正常工作?

I've tried something like: 我已经尝试过类似的东西:

private void button4_Click(object sender, EventArgs e)
{  
  richTextBox2.Select();
  richTextBox2.SelectedText = textBox1.ToString(); 
}

But it doesn't work. 但这是行不通的。 Who can help me? 谁能帮我?

Reverse it and add the Text property as the receiving part 反转它并将Text属性添加为接收部分

private void button4_Click(object sender, EventArgs e)
{
    textBox1.Text = richTextBox2.SelectedText; 
}

No need to call richTextBox2.Select(); 无需调用richTextBox2.Select();

You're going the wrong direction. 你走错了方向。 Should just be: 应该只是:

private void button4_Click(object sender, EventArgs e)
{  
    textBox1.Text = richTextBox2.SelectedText; 
}

This should work 这应该工作

private void button4_Click(object sender, EventArgs e)
    {  
        textBox1.Text = richTextBox2.SelectedText;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM