RichTextBox控件中如何出现不同颜色文字
能否给个实例,让该控件中的文字呈现不同的颜色RichTextBox1.SelColor=vbRed'可以了,再加个RichTextBox1.SelText...
能否给个实例,让该控件中的文字呈现不同的颜色
RichTextBox1.SelColor = vbRed'
可以了 ,再加个RichTextBox1.SelText 展开
RichTextBox1.SelColor = vbRed'
可以了 ,再加个RichTextBox1.SelText 展开
展开全部
protected override void OnTextChanged(EventArgs e)
{
if (boolLinkStyle)
{
int intCharIndex;
int intLine;
int intCurIdx;
string strLine;
char ch;
Font newFont;
Font oldFont;
Color oldColor;
oldFont = this.Font;
newFont = new Font(oldFont, FontStyle.Underline);
oldColor = this.ForeColor;
intCurIdx = this.SelectionStart;
this.SelectAll();
this.SelectionFont = oldFont;
this.SelectionColor = oldColor;
for (int i = 0; i < this.TextLength; i++)
{
ch = Convert.ToChar(this.Text.Substring(i, 1));
intCharIndex = i;
if (ch != '【' && ch != '】')
{
intLine = this.GetLineFromCharIndex(intCharIndex);
strLine = this.Text;
if ((strLine.Substring(0, intCharIndex).LastIndexOf("【") >= 0 && strLine.IndexOf("】", intCharIndex) >= 0) &&
((strLine.Substring(0, intCharIndex).LastIndexOf("【") >= 0 && strLine.IndexOf("【", intCharIndex) < 0) ||
(strLine.IndexOf("【", intCharIndex) > strLine.IndexOf("】", intCharIndex)) &&
(strLine.IndexOf("【", intCharIndex) >= 0 && (strLine.IndexOf("【", intCharIndex) > strLine.IndexOf("】", intCharIndex)))))
{
this.Select(intCharIndex, 1);
this.SelectionColor = Color.Blue;
this.SelectionFont = newFont;
}
}
}
this.Select(intCurIdx, 0);
}
base.OnTextChanged(e);
}
{
if (boolLinkStyle)
{
int intCharIndex;
int intLine;
int intCurIdx;
string strLine;
char ch;
Font newFont;
Font oldFont;
Color oldColor;
oldFont = this.Font;
newFont = new Font(oldFont, FontStyle.Underline);
oldColor = this.ForeColor;
intCurIdx = this.SelectionStart;
this.SelectAll();
this.SelectionFont = oldFont;
this.SelectionColor = oldColor;
for (int i = 0; i < this.TextLength; i++)
{
ch = Convert.ToChar(this.Text.Substring(i, 1));
intCharIndex = i;
if (ch != '【' && ch != '】')
{
intLine = this.GetLineFromCharIndex(intCharIndex);
strLine = this.Text;
if ((strLine.Substring(0, intCharIndex).LastIndexOf("【") >= 0 && strLine.IndexOf("】", intCharIndex) >= 0) &&
((strLine.Substring(0, intCharIndex).LastIndexOf("【") >= 0 && strLine.IndexOf("【", intCharIndex) < 0) ||
(strLine.IndexOf("【", intCharIndex) > strLine.IndexOf("】", intCharIndex)) &&
(strLine.IndexOf("【", intCharIndex) >= 0 && (strLine.IndexOf("【", intCharIndex) > strLine.IndexOf("】", intCharIndex)))))
{
this.Select(intCharIndex, 1);
this.SelectionColor = Color.Blue;
this.SelectionFont = newFont;
}
}
}
this.Select(intCurIdx, 0);
}
base.OnTextChanged(e);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询