線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1291
推到 Plurk!
推到 Facebook!

請教如何做?

 
lmk625
一般會員


發表:14
回覆:13
積分:5
註冊:2002-03-28

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-04-22 15:33:39 IP:203.75.xxx.xxx 未訂閱
想使用listbox 但是每項的字之顏色不同,該如何做才有此效果?
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-04-22 17:12:21 IP:211.22.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-04-23 11:10:21 IP:203.75.xxx.xxx 未訂閱
謝謝您!我會試試看的!
c905165
中階會員


發表:50
回覆:120
積分:54
註冊:2002-09-29

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-12-05 22:30:39 IP:203.204.xxx.xxx 未訂閱
假設不全然是整行是同一種顏色呢? 比如說 a:='abc' 'xyz'; 'abc' 要紅色,而'xyz'要黑色。 這要怎麼做?
------
有困難就是能力不足,有麻煩就是方法不對... 劣者總是遇到困難,也時常出現麻煩
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-12-06 07:51:22 IP:202.39.xxx.xxx 未訂閱
試試:
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.
系統時間:2024-04-26 4:17:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!