有關於Combobox與ListBox背景 |
答題得分者是:pceyes
|
cobraliu
中階會員 發表:15 回覆:75 積分:83 註冊:2007-11-22 發送簡訊給我 |
想做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 發送簡訊給我 |
//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 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |