简体   繁体   English

Delphi XE8 FireMonkey TMemo透明吗?

[英]Delphi XE8 FireMonkey TMemo Transparent?

Is there a way to make a TMemo's background transparent? 有没有办法使TMemo的背景透明? 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. 我尝试将不透明度从1设置为0,然后整个组件(包括文本)逐渐消失,然后在0处完全消失。在0.1时,背景框仍然可见。 I am currently using XE8 for iOS 8.3. 我当前正在使用XE8 for iOS 8.3。

Since TMemo is a TStyledControl you need to change its Style in order to make the background transparent. 由于TMemoTStyledControl您需要更改其Style以使背景透明。 In order to do so right click on the TMemo and select "Edit Custom Style". 为此,请右键单击TMemo然后选择“编辑自定义样式”。 This will open the Style Editor. 这将打开样式编辑器。 Look for the MemoStyle1 . 寻找MemoStyle1 As a child you will find a background of type TActiveStyleObject . 小时候,您会发现TActiveStyleObject类型的背景。 Add either a TLayout (The memo background will always be transparent) or eg a TRectangle (To have more control over color and transparency) to MemoStyle1. 在MemoStyle1中添加一个TLayout(备注背景将始终是透明的)或一个TRectangle(以更好地控制颜色和透明度)。 Change the added TLayout (or TRectangle) align property to contents and set its StyleName property to "background". 将添加的TLayout(或TRectangle)align属性更改为contents ,并将其StyleName属性设置为“ background”。 Now drag all the children from the original background TActiveStyleObject into your new background. 现在,将所有子项从原始背景TActiveStyleObject到新背景中。 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. 单击样式编辑器右上角的“应用并关闭”,您应该会在记事中看到效果。

  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;

I have tested the 2 posts from iamjoosy and DanielH. 我已经测试了iamjoosy和DanielH的2个帖子。 They both worked for iOS 8.3 and Android 5.02 他们都适用于iOS 8.3和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. 对于代码解决方案,只需将其插入要使其背景透明的TMemo的OnApplyStyleLookup事件处理程序中即可。 I leave the TMemo's StyleLookup property blank. 我将TMemo的StyleLookup属性留为空白。

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. 以前有XE4的代码解决方案,但对我来说不起作用,因为它测试资源对象是否是TSubImage而不是TActiveStyleObject。

Both answers are good, alternative solutions. 这两个答案都是很好的替代解决方案。

Thanks to the both of you. 多亏你们两个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM