var gStart, gLength, gCol: Integer; procedure SetRichEdit(aRichEdit: TRichEdit); var fRow, fCol: Integer; fStart, fLength, tStart: Integer; begin fRow := aRichEdit.CaretPos.X; fCol := aRichEdit.CaretPos.Y; if gCol = fCol then Exit; if Self.SelLength > 0 then Exit; tStart := aRichEdit.SelStart; fStart := tStart - fRow; fLength := aRichEdit.Lines[fCol].Length; aRichEdit.Lines.BeginUpdate; if fLength > 0 then begin aRichEdit.SelStart := fStart; aRichEdit.SelLength := fLength; aRichEdit.SelAttributes.Color := clRed; end; if gLength > 0 then begin aRichEdit.SelStart := gStart; aRichEdit.SelLength := gLength; // aRichEdit.SelectAll; aRichEdit.SelAttributes.Color := clBlack; end; aRichEdit.SelStart := tStart; aRichEdit.SelLength := 0; aRichEdit.Lines.EndUpdate; gStart := fStart; gLength := fLength; gCol := fCol; end; procedure TForm1.RichEdit1Click(Sender: TObject); begin SetRichEdit(TRichEdit(Sender)); end; procedure TForm1.RichEdit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key in [37..40] then SetRichEdit(TRichEdit(Sender)); end;
設置 >> 語言格式設置:
(選擇你要改動的主題;)
語言:Global Styles
Style: Current line background color
若仍未解決,請“補充說明”或“追問”,我繼續幫你。
選中一個變量後,按 shift + F8 可以使變量高亮為黃色,很方便!