C# RichEditControl中的注释/取消注释功能
我已经创建了一个应用程序,可以对突出显示的行或当前行进行注释或取消注释,并将该行涂成绿色。我有两个按钮,一个用于注释,一个用于取消注释。这是我的密码C# RichEditControl中的注释/取消注释功能,c#,winforms,devexpress,richedit-control,C#,Winforms,Devexpress,Richedit Control,我已经创建了一个应用程序,可以对突出显示的行或当前行进行注释或取消注释,并将该行涂成绿色。我有两个按钮,一个用于注释,一个用于取消注释。这是我的密码 DocumentRange lineRange = null; bool isSelectionLocked = false; void SetLineRangeFormatting(DocumentRange currentLineRange, System.Drawing.Color rangeColor) {
DocumentRange lineRange = null;
bool isSelectionLocked = false;
void SetLineRangeFormatting(DocumentRange currentLineRange, System.Drawing.Color rangeColor)
{
CharacterProperties cp = richEditControl1.Document.BeginUpdateCharacters(currentLineRange);
cp.ForeColor = rangeColor;
richEditControl1.Document.EndUpdateCharacters(cp);
}
DocumentRange GetNewLineRange(DocumentPosition caret)
{
isSelectionLocked = true;
DocumentPosition currentPosition = richEditControl1.Document.CaretPosition;
StartOfLineCommand startOfLineCommand = new StartOfLineCommand(richEditControl1);
EndOfLineCommand endOfLineCommand = new EndOfLineCommand(richEditControl1);
startOfLineCommand.Execute();
int start = richEditControl1.Document.CaretPosition.ToInt();
endOfLineCommand.Execute();
int length = richEditControl1.Document.CaretPosition.ToInt() - start;
DocumentRange range = richEditControl1.Document.CreateRange(start, length);
DocumentRange range2 = richEditControl1.Document.CreateRange(start, length + 1);
string text = richEditControl1.Document.GetText(range2);
richEditControl1.Document.CaretPosition = currentPosition;
isSelectionLocked = false;
if (text.EndsWith(Environment.NewLine))
{
return range2;
}
else
{
return range;
}
}
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (isSelectionLocked) return;
if (!lineRange.Contains(richEditControl1.Document.CaretPosition))
{
//SetLineRangeFormatting(lineRange, System.Drawing.Color.Transparent);
lineRange = GetNewLineRange(richEditControl1.Document.CaretPosition);
SetLineRangeFormatting(lineRange, System.Drawing.Color.Green);
}
}
private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
}
但是它不能正常工作,请帮助我是新手,我在devexpress中研究它,但我没有找到这样做的方法谢谢,那里的支持没有回答我的问题我不知道如何在每一行或选定的行上添加“/”。。先生,请帮帮我有人帮我解决问题吗?我有股票