问题
How can I change SelectionBackColor of richtext box to "no color"?
I tried these:
Color.FromArgb(0, 255, 255, 255);
Color.Empty;
Color.White;
Color.Transparent;
But they are all return same result: Color.White !!!
For more description, change richtextbox backcolor to some color like pink, then change SelectionBackColor to red, now, try to remove SelectionBackColor, you see that the color will be white. please note that it is not true to change SelectionBackColor to pink in this example :D !!!
回答1:
I'd need some clarification on what you mean by "no color". Do you mean transparent?
You can set the SelectionBackColor back to the default color: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.defaultbackcolor(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionbackcolor(v=vs.110).aspx
回答2:
It is not magic
richTextBox1.SelectionBackColor = richTextBox1.BackColor;
valter
回答3:
Well i had same problem too, finally i used that code:
richTextBox.Text = richTextBox.Text.Replace(richTextBox.SelectedText, richTextBox.SelectedText);
this works for background but deletes all other format too (underline, bold etc..)
回答4:
Maybe a bit late, but i just noticed if you write
this.richTextBox.SelectedText = "\r";
the RTF loses all formatting for the following texts, including the SelectionBackColor.
e.g.
this.richTextBox.SelectionBackColor = Color.Yellow;
this.richTextBox.SelectedText = "the damn yellow backcolor is set";
this.richTextBox.SelectedText = "\r";
this.richTextBox.SelectedText = "now i have transparent backcolor again and the default text";
来源:https://stackoverflow.com/questions/22359315/remove-richtextbox-selectionbackcolor