2013-11-25 4 views
8

같은 줄이지만 다른 색상으로 텍스트를 쓰는 방법은 무엇입니까? (내가 richedit을 사용).TRichEdit의 같은 줄에있는 다채로운 텍스트

procedure TForm1.btnEClick(sender: TObject); 
begin 

    m0.SelAttributes.Color := clBlue; 
    m0.SelAttributes.Style := [fsBold]; 
    m0.lines.add('This is blue and it is bold'); 
    m0.SelAttributes.Color := clGreen; 
    m0.SelAttributes.Style := [fsBold]; 
    m0.lines.add ('This is Green and it is bold'); 
    m0.lines.add(''); 
    m0.lines.add('But how to write text in the same line with different color?'); 
    // i want to have both blue and green in the same line 
end; 

빌며, 꿀벌 당신이 올바른 궤도에있어

답변

16

. 그냥 SelAttributes을 변경하고 SelText 대신 Lines.Add의 사용

procedure TForm4.FormCreate(Sender: TObject); 
begin 
    RichEdit1.Clear; 
    RichEdit1.SelAttributes.Color := clBlue; 
    RichEdit1.SelAttributes.Style := [fsBold]; 
    RichEdit1.SelText := 'This is bold blue text.'; 
    RichEdit1.SelAttributes.Color := clRed; 
    RichEdit1.SelAttributes.Style := [fsItalic]; 
    RichEdit1.SelText := #32'This is italic red text'; 
end; 

이 생산

Sample output from code above