2014-01-08 3 views
1

내 질문은 기본적으로이 question과 같습니다. 그러나, 나는 왼쪽에서 오른쪽으로 설정된 색상에서 흰색으로 색상 흐름을 만들고 싶습니다. 아이디어는 모든 항목을 100 %로 채우고 점차적으로 색상을 녹색에서 노란색으로 빨간색으로 변경한다는 것입니다.다른 색상의 목록 상자에 항목을 그리는 방법

+0

을 ['그라데이션이 Canvas'에 기입 그리는 방법 (http://delphi.about.com/od/ adptips2006/qt/gradient_fill.htm). 또한 GraphUtil.pas에'GradientFillCanvas'가 있습니다. –

+0

위대한 m8. 이 tnx를 배울 것입니다. – Eszee

+0

@ LURD의 팁과 함께 ListBox 아이템을 다르게 사용자 정의하는 코드가 있습니다. 두 가지를 합치면 해결책이 있어야합니다. :-) –

답변

0

이 코드를보십시오 : 참조 그라데이션 채우기를 수행하는 간단한 절차

unit Unit1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls; 

type 
    TForm1 = class(TForm) 
    Button1: TButton; 
    Button2: TButton; 
    ListBox1: TListBox; 
    procedure Button1Click(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; 
     Rect: TRect; State: TOwnerDrawState); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    procedure AddLog(const aStr : String; const aColor : TColor); 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.AddLog(const aStr: String; const aColor: TColor); 
begin 
    ListBox1.Items.AddObject(aStr, TObject(aColor)); 
end; 

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; 
    Rect: TRect; State: TOwnerDrawState); 
var 
    OldColor : TColor; 
begin 
    with ListBox1.Canvas do begin 
    OldColor := Font.Color; 
    Font.Color := TColor(ListBox1.Items.Objects[Index]); 
    TextOut(Rect.Left, Rect.Top, ListBox1.Items[Index]); 
    Font.Color := OldColor; 
    end; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    Randomize; 
    AddLog(
    'String #' + IntToStr(ListBox1.Items.Count), 
    RGB(Random(11) * 20 , Random(11) * 20, Random(11) * 20) 
); 
end; 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
    ListBox1.Clear; 
end; 

end. 
+0

OP는 그라데이션으로 채워진 목록 상자 항목 배경을 원합니다. 끝 색상은 흰색이고 시작 색상은 녹색에서 노란색에서 빨간색까지 0에서 100 %까지의 그래디언트 비율로 다양합니다. –

+0

@LURD 참조 ... 감사합니다! – huxahetu

관련 문제