Autor Beitrag
Hippo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 49



BeitragVerfasst: Sa 25.12.04 21:02 
Hallo,

wie kann ich in einem RichEdit einen Text von einem bestimmten Zeichen zu einem anderen farblich ändern?
Der restliche Text soll seine Ursprungsfarbe beibehalten.


Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am Mo 27.12.2004 um 14:28
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Sa 25.12.04 21:09 
Schau dir mal in der Hilfe zu TRichEdit die Eigenschaft SelAttributes an. ;-)

Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Hippo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 49



BeitragVerfasst: Sa 25.12.04 21:29 
Wenn ich alles richtig verstanden habe, dann geht das nur, wenn ein Text markiert ist? Und ich möchte, dass der Text von sich aus eine bestimmte Farbe annimmt, wenn er zwischen zwei bestimmten Zeichen steht.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Sa 25.12.04 21:50 
Hippo hat folgendes geschrieben:
Wenn ich alles richtig verstanden habe, dann geht das nur, wenn ein Text markiert ist? Und ich möchte, dass der Text von sich aus eine bestimmte Farbe annimmt, wenn er zwischen zwei bestimmten Zeichen steht.

Was glaubst du, was ich alles möchte, wenn der Tag lang ist? :P Dann überwache den Text, z.B. im OnChange, und markiere ihn dort, setze die Farbe, und entmarkiere ihn wieder.

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
EUOCheffe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 124



BeitragVerfasst: Mo 27.12.04 18:16 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
procedure SelectLine(RE : TRichEdit; Line : Integer);
var
  i : Integer;
begin
  RE.Perform(EM_HIDESELECTION,1,0);
  RE.SelectAll;
  //RE.SelAttributes.Color:=clBlack;
  RE.SelAttributes.Style:=[];
  if Line<1 then Exit;

  i:=0;
  while Line>1 do
  begin
    if RE.Lines[i]='' then Dec(Line);
    Inc(i);
  end;

  RE.SelStart:=RE.Perform(EM_LINEINDEX,i,0);
  repeat
    Inc(i);
  until RE.Lines[i]='';

  RE.SelLength:=RE.Perform(EM_LINEINDEX,i,0)-RE.SelStart;
  //RE.SelAttributes.Color:=clBlack;
  RE.SelAttributes.Style:=[fsBold];
end;

var
  sSelStart,
  sSelLength : Integer;
  sFirstLine : Integer;

procedure SaveCurPos(var ScrMemo : TRichEdit; Save : Boolean);
var
  iBuf : Integer;
begin
  if Save then
  begin //der Teil hier speichert
    sSelStart:=ScrMemo.SelStart;
    sSelLength:=ScrMemo.SelLength;
    sFirstLine:=ScrMemo.Perform(EM_GETFIRSTVISIBLELINE,0,0);
  end
  else begin //dieser Teil sorgt für die Wiederherstellung
    ScrMemo.SelStart:=sSelStart;
    ScrMemo.SelLength:=sSelLength;
    iBuf:=ScrMemo.Perform(EM_GETFIRSTVISIBLELINE,0,0);
    ScrMemo.Perform(EM_LINESCROLL,0,sFirstLine-iBuf);
  end;

end;


Ich hab hier zwei Prozeduren, die ich in meinem Code mal irgendwo verwendet hab. Vielleicht kannst du daraus was zusammenbasteln. Am besten, du guckst dir auch mal die WinApi Hilfe zu den benutzten EM_ Messages an.