可以通过以下步骤实现:
private void richTextBox_TextChanged(object sender, EventArgs e)
{
HighlightCurrentLine();
}
private void HighlightCurrentLine()
{
int lineIndex = richTextBox.GetLineFromCharIndex(richTextBox.SelectionStart);
int lineStart = richTextBox.GetFirstCharIndexFromLine(lineIndex);
int lineEnd = richTextBox.GetFirstCharIndexFromLine(lineIndex + 1);
richTextBox.SelectionStart = lineStart;
richTextBox.SelectionLength = lineEnd - lineStart;
richTextBox.SelectionBackColor = Color.Yellow;
}
private void Form_Load(object sender, EventArgs e)
{
richTextBox.TextChanged += richTextBox_TextChanged;
}
这样,每当在RichTextBox中输入或编辑文本时,当前行将以黄色背景突出显示。你可以根据需要自定义突出显示的颜色和样式。
推荐的腾讯云相关产品:腾讯云云服务器(CVM)
领取专属 10元无门槛券
手把手带您无忧上云