全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2306
推到 Plurk!
推到 Facebook!

有關於Combobox與ListBox背景

答題得分者是:pceyes
cobraliu
中階會員


發表:15
回覆:75
積分:83
註冊:2007-11-22

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-02-28 16:07:23 IP:220.143.xxx.xxx 訂閱
想做Combobox與ListBox使其背景顏色
因Index的不同給予不同的顏色
而現在是有實做出來
但卡在一個問題
當用Mouse去拉Scroll Bar 時,整個顏色
會亂掉,去測試懷疑為Indexitem實際上
沒有跟著Scroll Bar跑,所以導致顏色沒
有重新分配。
想問問各位大大,有什麼方式去改可以
改進Combobox使其顏色可以重新的分配好。
而ListBox的問題跟Combobox一樣,另它更
是產生另一個畫面會一直閃爍的問題..Orz

Combobox程式碼

[code delphi]
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
TempData:String;
begin
TempData := (Control as TComboBox).Items[index];

With (Control as TComboBox) Do
BEGIN
case (index mod 4) of
0:Color :=clblack;
1:Color :=clBlue;
2:Color :=clRed;
3:Color :=clWindow;
Else
Color :=clWindow;
end;
End;

With (Control as TComboBox).Canvas DO
BEGIN
FillRect(Rect);
font.Color := clyellow;
TextOut(Rect.Left,Rect.Top,LeftStr(TempData,Length(TempData)-1));
TextOut(PenPos.X,Rect.Top,RightStr(TempData,1));
END;
end;

[/code]

ListBox程式碼

[code delphi]
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
TempData:String;
begin
TempData := (Control as TListBox).Items[index];

With (Control as TListBox) Do
BEGIN
case (index mod 4) of
0:Color :=clblack;
1:Color :=clBlue;
2:Color :=clRed;
3:Color :=clWindow;
Else
Color :=clWindow;
end;
End;

With (Control as TListBox).Canvas DO
BEGIN
FillRect(Rect);
font.Color := clyellow;
TextOut(Rect.Left,Rect.Top,LeftStr(TempData,Length(TempData)-1));
TextOut(PenPos.X,Rect.Top,RightStr(TempData,1));
END;
end;

[/code]
------
初學、初學、學了很久...還是在初學階段..Orz
pceyes
尊榮會員


發表:70
回覆:657
積分:1140
註冊:2003-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-02-29 14:30:31 IP:122.127.xxx.xxx 訂閱
//Combobox.Style := csOwnerDrawFixed;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ComboBox1 do //TCombobox oder T.....box
begin
case (index mod 4) of
0:Canvas.Brush.color :=clblack;
1:Canvas.Brush.color :=clBlue;
2:Canvas.Brush.color :=clRed;
3:Canvas.Brush.color :=clWindow;
end;
Canvas.FillRect(Rect);
Canvas.Font.Color := clyellow;;
Canvas.TextOut(Rect.Left,Rect.Top,Items[Index]);
end;
end;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
TempData:String;
begin
TempData := (Control as TListBox).Items[index];
Canvas.Brush.Color :=clblack;
1: With (Control as TListBox).Canvas DO
BEGIN
FillRect(Rect);
font.Color := clyellow;
TextOut(Rect.Left,Rect.Top,LeftStr(TempData,Length(TempData)-1));
TextOut(PenPos.X,Rect.Top,RightStr(TempData,1));
END;
end;




------
努力會更接近成功
編輯記錄
pceyes 重新編輯於 2008-02-29 14:40:28, 註解 無‧
cobraliu
中階會員


發表:15
回覆:75
積分:83
註冊:2007-11-22

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-02-29 15:58:52 IP:59.127.xxx.xxx 訂閱
感謝大大,讓我了解兩個方式差異
------
初學、初學、學了很久...還是在初學階段..Orz
系統時間:2024-09-09 20:15:29
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!