0
Dev-C++ 및 다른 IDE에서 커서가있는 전체 행을 강조 표시하려고합니다. 텍스트를 강조 표시하지 않고 컨트롤의 전체 행에서 투명한 색을 그립니다. 여기에 내가RichTextBox의 현재 행 강조 표시
Dev-C++ 및 다른 IDE에서 커서가있는 전체 행을 강조 표시하려고합니다. 텍스트를 강조 표시하지 않고 컨트롤의 전체 행에서 투명한 색을 그립니다. 여기에 내가RichTextBox의 현재 행 강조 표시
int lastLine = 0;
private void HighlightCurrentLine()
{
// Save current selection
int selectionStart = rtb.SelectionStart;
int selectionLength = rtb.SelectionLength;
// Get character positions for the current line
int firstCharPosition = rtb.GetFirstCharIndexOfCurrentLine();
int lineNumber = rtb.GetLineFromCharIndex(firstCharPosition);
int lastCharPosition = rtb.GetFirstCharIndexFromLine(lineNumber + 1);
if (lastCharPosition == -1)
lastCharPosition = rtb.TextLength;
// Clear any previous color
if (lineNumber != lastLine)
{
int previousFirstCharPosition = rtb.GetFirstCharIndexFromLine(lastLine);
int previousLastCharPosition = rtb.GetFirstCharIndexFromLine(lastLine + 1);
if (previousLastCharPosition == -1)
previousLastCharPosition = rtb.TextLength;
rtb.SelectionStart = previousFirstCharPosition;
rtb.SelectionLength = previousLastCharPosition - previousFirstCharPosition;
rtb.SelectionBackColor = SystemColors.Window;
lastLine = lineNumber;
}
// Set new color
rtb.SelectionStart = firstCharPosition;
rtb.SelectionLength = lastCharPosition - firstCharPosition;
if (rtb.SelectionLength > 0)
rtb.SelectionBackColor = Color.PaleTurquoise;
// Reset selection
rtb.SelectionStart = selectionStart;
rtb.SelectionLength = selectionLength;
}
코드 MSDN
에서 이것은 내가 ... 내가 텍스트를 선택하지 않으 싶지 않았다 정확히 수행 할거야하지만 난 전체 라인을 원하는 강조 표시되고 선택되지 않음. – tr0yspradling