請教如何做? |
|
lmk625
一般會員 發表:14 回覆:13 積分:5 註冊:2002-03-28 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
1.將 ListBox1 的 Style 屬性設為 lbOwnerDrawVariable
2.在 ListBox1 的 OnDrawItem 事件:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do begin
FillRect(Rect);
case Index of
0: Font.Color := clRed;
1: Font.Color := clLime;
2: Font.Color := clBlue;
end;
TextOut(Rect.Left 1, Rect.Top 1, ListBox1.Items[Index]);
end;
end;
|
lmk625
一般會員 發表:14 回覆:13 積分:5 註冊:2002-03-28 發送簡訊給我 |
|
c905165
中階會員 發表:50 回覆:120 積分:54 註冊:2002-09-29 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
試試:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var sTmp: string; iTextWidth: integer; begin with ListBox1.Canvas do begin FillRect(Rect); sTmp := Copy(ListBox1.Items[Index], 1, 3); iTextWidth := TextWidth(sTmp); Font.Color := clRed; TextOut(Rect.Left 1, Rect.Top 1, sTmp); sTmp := Copy(ListBox1.Items[Index], 4, 3); Font.Color := clYellow; TextOut(Rect.Left 1 iTextWidth, Rect.Top 1, sTmp); end; end;-- Everything I say is a lie. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |