Jro
Jro

Reputation: 135

Set text alignment listboxitem Delphi XE5 FM during runtime not working

I want to change the alignment of a litboxitem that is creatd at runtim and added to a simple listbox.

listboxitem1.VertTextAlign := TTextAlign.taTrailing;
listboxitem1.TextAlign := TTextAlign.taCenter;

listboxitem2 := Tlistboxitem.Create(self);
listboxitem2.Text := 'itemtext';
listboxitem2.Height := 100;
listboxitem2.VertTextAlign := TTextAlign.taTrailing;
listboxitem2.TextAlign := TTextAlign.taCenter;
listboxitem2.Name := 'itemname';
listbox1.AddObject(listboxitem2);

What is wrong about this code?

Upvotes: 1

Views: 2105

Answers (1)

Mike Sutton
Mike Sutton

Reputation: 4211

Settings such as this are normally pulled from the style. The StyledSettings property tells FM which properties should be pulled from the style, others will be set from properties. If you edit a property at design time the editor will adjust the StyledSettings property for you. At run time you need to do that manually.

Try adding:

listboxitem2.StyledSettings := listboxitem2.StyledSettings - [TStyledSetting.ssOther];

Upvotes: 2

Related Questions