我的问题与此基本相同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项目[这里];如果你将这两者结合起来,你应该有你的解决方案。 :-) –