有一堆字符串要用类似标题上说的两个控件来显示。我想把每一行的字体大小和颜色可以定义。类似聊天室的东西,怎样做?
解决方案 »
- delphi DLL动态调用.的@有何作用?求解
- 那里有比较经典,比较专业的专家系统编程书籍,最好有例子
- 用 HOOK 如何阻止弹出窗口?
- 简单问题,进来看看吧.在线等待...
- 一个菜单条添加问题?
- 请问,我打印发票时到最末行,打印机总认为我缺纸,不能打印最后一行,怎么解决呢?60分在线急等,谢谢!!!
- 如何将数据库中查询得到的数据集导入到Excel中?
- Ado报“bof或Eof其中一个为真“错误怎么解决?
- Delphi中可以使用控件数组吗?
- 很简单的问题:如何使窗体接受拖动过来的文本(就是有接受焦点)
- TStringList的一个很不完善的地方(字符分割问题)
- 连接Oracle一般用什么组件???
只在两个事件中写代码即可:procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
Height := Index Mod 3 * 2 + ListBox1.ItemHeight;
//你要画的每个Item的高度,根据字体不同而不同,这是随便取了几个不同的值
end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
ListBox1.Canvas.Brush.Color := Index * $A0F0F0;
ListBox1.Canvas.FillRect(Rect);
//上面的代码是填充Item的背景,下面画出每个Item的文字,可以为每个Item设置不同的字体及着色
if Index mod 2 = 0 then
begin
ListBox1.Canvas.Font.Name := 'Impact';
ListBox1.Canvas.Font.Color := clLime;
end
else
begin
ListBox1.Canvas.Font.Name := 'Tahoma';
ListBox1.Canvas.Font.Color := clRed;
end;
//用Canvas的TextOut画出文字:
ListBox1.Canvas.TextOut(Rect.Left, Rect.Top, ListBox1.Items[Index]);
end;
var
s: string;
begin
s:= 'sdfsdf';
RichEdit1.SelAttributes.Color := clRed;
RichEdit1.Lines.Add(s);
RichEdit1.SelAttributes.Color := clBlue;
RichEdit1.Lines.Add(s);
end;