我的問題與此基本相同question。但是,我想讓顏色從左到右從設置的顏色流向白色。這個想法是,我想「填充」每個項目100%,逐漸將顏色從綠色變爲黃色變爲紅色。如何在不同顏色的列表框中繪製項目
1
A
回答
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
相關問題
- 1. 如何顏色列表框項目?
- 2. 列表框項目WPF,不同項目的不同背景顏色
- 3. 顏色繪製不同的顏色matplotlib
- 4. 如何繪製不同顏色的點?
- 5. 如何繪製不同的顏色
- 6. 在列表框中繪製項目
- 7. 如何更改列表框中未選中的項目顏色
- 8. 在Mathematica中繪製用不同顏色表格的不同條目
- 9. 如何更改列表框中項目的字體顏色(wpf)
- 10. 如何設置列表框中項目的顏色
- 11. 如何更改列表框中項目的文本顏色
- 12. C#:更改列表框項目顏色
- 13. 我的列表中的某個項目的顏色不同
- 14. 如何在按下JButton後更改繪製項目的顏色?
- 15. 如何在d3中繪製不同顏色的圖形wpf
- 16. 在Java中,如何繪製兩個不同顏色的矩形?
- 17. 如何更改所選項目(對象)中的列表框項目顏色?
- 18. 如何在Matplotlib中以不同顏色繪製
- 19. MFC:繪製不同顏色的線
- 20. 繪製不同的顏色 - Scilab
- 21. 如何繪製多個ECDF在R中的不同顏色的一個繪圖
- 22. 如何使用不同的顏色來繪製信號在Matlab
- 23. 如何重用與不同顏色的定義繪製在XML
- 24. 如何在leaflet.js上繪製不同顏色的路徑疊加?
- 25. WP7列表框選擇的項目不會改變顏色
- 26. 如何在R中繪製顏色圖
- 27. 如何在Matlab中繪製顏色塊
- 28. 離子框架:每個列表項的不同背景顏色
- 29. 可擴展列表:ListGroup項目的不同背景顏色
- 30. 如何設置不同的顏色不同的列表視圖項在kendoUI
對於一個簡單的過程,做漸變填充,請參閱['如何繪製漸變上Canvas'填充](http://delphi.about.com/od/ adptips2006/QT/gradient_fill.htm)。 'GraphUtil.pas'中也有'GradientFillCanvas'。 –
這就是偉大的M8。要學習這個tnx – Eszee
並且@LURD的提示,還有代碼來自定義繪製ListBox項目[這裏];如果你將這兩者結合起來,你應該有你的解決方案。 :-) –