TListView中如何让其中的某些Item的字体变粗?

acqy 2005-03-17 04:17:55
如题,想要在Button1按下的时候使得ListView中的某一个Item的字体变粗,或者改变字体的颜色等,应该如何做?
...全文
151 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzmhero 2005-03-17
  • 打赏
  • 举报
回复
下面的代码能够让你设定所有串为Edit1.Text值的Item字体改变。包括Caption和SubItem都会变。
var
Form1: TForm1;
strPos:string;

implementation

{$R *.dfm}

procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
if Item.SubItems[SubItem-1]=strPos then
begin
ListView1.Canvas.Font.Color:=clred;
ListView1.Canvas.Font.Style:=[fsBold];
end else
ListView1.Canvas.Font.Color:=clBlack;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
strPos:=Edit1.Text;
ListView1.Refresh;
end;

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Item.Caption=strPos then
begin
ListView1.Canvas.Font.Color:=clred;
ListView1.Canvas.Font.Style:=[fsBold];
end else
ListView1.Canvas.Font.Color:=clBlack;
end;
lyguo 2005-03-17
  • 打赏
  • 举报
回复
帮你顶
何鲁青 2005-03-17
  • 打赏
  • 举报
回复
up...

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧