我为RichTextBox创建了一个ToolStrigMenuItem.在它的Click事件中,我将剪贴板中的一些文本粘贴到RichTextBox中.
The problem is that in the Form Designer the ForeColor
of the RichTextBox is set to Color.Yellow
, but if the text in the Clipboard contains different colors, some sections of the text won't be visible all, because the BackColor of the RichTextBox is black.
I want to select the pasted text and color it in yellow.
这是我粘贴文本的事件:
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
// Handle the Paste event
richTextBox1.Paste();
// Set the desired formatting (e.g., yellow color) for the pasted text
richTextBox1.SelectionColor = Color.Yellow;
}
我试着添加了这句话:
richTextBox1.SelectionColor = Color.Yellow;
但这并没有解决任何问题.
Here is a screenshot example of text I paste in the RichTextBox. The text in the Clipboard is partially colored in blue and brown.
The brown color is swallowed in the black background and the blue is hard to see. I want it all to be in yellow.
如何更改代码,以便无论粘贴到RichTextBox中的文本是什么,都将使用RichTextBox ForeColor
进行着色?