2
votes

Is there a way to make a TMemo's background transparent? I tried setting Opacity to from 1 down to 0 and the whole component (including text) gradually fades then completely disappears at 0. At 0.1 the background box is still visible. I am currently using XE8 for iOS 8.3.

3

3 Answers

3
votes

Since TMemo is a TStyledControl you need to change its Style in order to make the background transparent. In order to do so right click on the TMemo and select "Edit Custom Style". This will open the Style Editor. Look for the MemoStyle1. As a child you will find a background of type TActiveStyleObject. Add either a TLayout (The memo background will always be transparent) or e.g. a TRectangle (To have more control over color and transparency) to MemoStyle1. Change the added TLayout (or TRectangle) align property to contents and set its StyleName property to "background". Now drag all the children from the original background TActiveStyleObject into your new background. Delete now the original background. Note: In oder to delete objects in the style editor you need to select the object and then use the delete button at the top of the style list. Click Apply and Close in the upper right hand corner of the style editor and you should see the effect on your memo.

0
votes
  uses FMX.Styles.Objects;

procedure TForm1.Memo1ApplyStyleLookup(Sender: TObject);
  Var
  Obj: TFmxObject;
begin

  Obj := Memo1.FindStyleResource('background');

  if Assigned(Obj) And ( Obj is TActiveStyleObject ) Then
  TActiveStyleObject(Obj).Source := Nil;

end;
0
votes

I have tested the 2 posts from iamjoosy and DanielH. They both worked for iOS 8.3 and Android 5.02

For the code solution, simply insert it into the OnApplyStyleLookup event handler of the TMemo which you want to make its background transparent. I leave the TMemo's StyleLookup property blank.

There was a previous code solution for XE4 but it didn't work for me because it tests whether the resource object is a TSubImage instead of a TActiveStyleObject.

Both answers are good, alternative solutions.

Thanks to the both of you.