如何更改richtextbox所选的文字颜色?
当用鼠标选择文字并通过点击上下文菜单项来改变颜色时!
private void ContextMenuItem_Click(object sender, EventArgs e)
{
ColorDialog c = new ColorDialog();
if (c.ShowDialog() == DialogResult.OK)
{
if (text.SelectedText != null)
{
// how coding for here?
}
}
}
答案 0 :(得分:2)
这应该有效
if(!string.IsNullOrEmpty(text.SelectedText))
{
text.SelectionColor = c.Color;
}