【问题标题】:How can I change the Font of a TListBox Items?如何更改 TListBox 项目的字体?
【发布时间】:2023-01-20 21:45:33
【问题描述】:
我正在 RAD Studio 11 上构建应用程序,但找不到更改 TListBox 的项目字体的方法
我试图在对象检查器上更改 TListBox 字体,但是当我在对象检查器上选择名为 ingredientsDataBase 的 TListBox 时,我可以只更改 TListBox 设置而不是 TListBox 项目设置。
我“手动”添加了一个 ListBoxItem,如下所示:
然后我可以在对象检查器上更改 ListBoxItem1 字体,在选择我的 ListBoxItem1 之后(没问题)
问题是当我运行我的程序时,字体更改只影响我的 ListBox 项目 1,我希望我在 TListBox 上添加的每个项目都使用相同的字体
【问题讨论】:
标签:
c++builder
rad-studio
【解决方案1】:
当你向列表框添加项目时,如果你想修改相应的TextSettings,你需要从新项目的默认StyledSettings属性中清除一些项目。
这是 Delphi 中的一个示例,可以执行您想要的操作:
procedure TForm5.Button2Click(Sender: TObject);
var
lbItem: TListBoxItem;
begin
lbItem := TListBoxItem.Create(ListBox1);
lbItem.Parent := ListBox1;
// Remove Family and Size from the items TStyledSettings
lbItem.StyledSettings := lbItem.StyledSettings - [TStyledSetting.Family,TStyledSetting.Size];
// You can now set these TextSettings as needed
lbItem.TextSettings.Font.Family := 'Algerian';
lbItem.TextSettings.Font.Size := 18;
lbItem.Text := 'algerian';
// In Embarcadero C++Builder you use the ">>" operator to remove members from a set, and "<<" to include them.
end;