求助:如何指定MEMO.lins.strings[i] (任意一行)得颜色 想在ADD得时候 如果Memo1.Lines.Add('正常')得时候 这个正常就是绿色 如果Memo1.Lines.Add('不正常')得时候 这个正常就是红色 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Memo不支持每行颜色的设定,改用RichEdit,SelAttributes属性... 就算我用 RichEdit那么 怎么指定第 i 行得颜色? 使用ListBox, Style 设为 lbOwnerDrawFixedOnDrawItem 自己画procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);var s: String;begin s := ListBox1.Items.Strings[Index]; if s = '正常' then ListBox1.Canvas.Font.Color := clGreen else if s = '不正常' then ListBox1.Canvas.Font.Color := clRed else ListBox1.Canvas.Font.Color := clBlack; ListBox1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, ListBox1.Items.Strings[Index]);end; 如果用RichEdit,可以这样:with RichEdit1 do begin SelAttributes.Color:=clGreen; Lines.Add('正常'); SelAttributes.Color:=clRed; Lines.Add('不正常'); end; 先别管正常 不正常 我就就想: 比如 我就想指定 RichEdit 的第5行 颜色是 clred怎做? procedure CrnSetRichEditLineColor(re: TRichEdit; cl: TColor; nRow: Integer);var nStartPos, nEndPos: integer;begin if nRow < 0 then nRow := 0; if nRow > re.Lines.Count - 1 then begin nRow := re.Lines.Count - 1; nStartPos := re.Perform(EM_LINEINDEX, nRow, 0); nEndPos := Length(re.Lines.Text); end else begin nStartPos := re.Perform(EM_LINEINDEX, nRow, 0); nEndPos := re.Perform(EM_LINEINDEX, nRow + 1, 0); end; re.SelStart := nStartPos; re.SelLength := nEndPos - nStartPos; re.SelAttributes.Color := cl;end;procedure TForm1.Button1Click(Sender: TObject);begin CrnSetRichEditLineColor(RichEdit1, clRed, 4);end; idhttp1 如何设置代理IP和端口 delphi7下测试 心情靓散分 如何提高获取数据的速度? 是一行行的字符串组成的字符串,如何按照行分离开? 高分求助:如何让delphi自带的mediaplayer放慢速度播放声音文件,如wav,mp3格式等? 如何在delphi中修改DBE中的DataBase Name?? 三層結構,客戶端程序如何操作數據表(添加 修改 刪除 查詢等等) 高手请进!(在线等候,立即送分) 请问CSDN有哪些DELPHI高手,特别是数据库方面的. 50分简单问题? 得到cxGrid被选(多选)后的字段内容 還夠散2次分,都散光了吧!
那么 怎么指定第 i 行得颜色?
OnDrawItem 自己画
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
s: String;
begin
s := ListBox1.Items.Strings[Index];
if s = '正常' then
ListBox1.Canvas.Font.Color := clGreen
else if s = '不正常' then
ListBox1.Canvas.Font.Color := clRed
else
ListBox1.Canvas.Font.Color := clBlack;
ListBox1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, ListBox1.Items.Strings[Index]);
end;
with RichEdit1 do
begin
SelAttributes.Color:=clGreen;
Lines.Add('正常');
SelAttributes.Color:=clRed;
Lines.Add('不正常');
end;
var
nStartPos, nEndPos: integer;
begin
if nRow < 0 then
nRow := 0;
if nRow > re.Lines.Count - 1 then
begin
nRow := re.Lines.Count - 1;
nStartPos := re.Perform(EM_LINEINDEX, nRow, 0);
nEndPos := Length(re.Lines.Text);
end
else
begin
nStartPos := re.Perform(EM_LINEINDEX, nRow, 0);
nEndPos := re.Perform(EM_LINEINDEX, nRow + 1, 0);
end; re.SelStart := nStartPos;
re.SelLength := nEndPos - nStartPos;
re.SelAttributes.Color := cl;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
CrnSetRichEditLineColor(RichEdit1, clRed, 4);
end;