如何让我的禁用控件不透明?

问题描述 投票:2回答:3

我注意到,当我禁用控件(controlName.enabled := false;)时,它们会自动变为半透明。

有没有办法可以强制它们保持不透明?

我尝试过controlName.Opacity := 1;,但似乎没有做任何事情。

我也尝试将控件嵌入到TLayout中,然后禁用TLayout,但是半透明似乎被嵌入式控件拾取。

[编辑]

这是我所看到的一个例子在这种情况下,它覆盖了一个包含大国会大厦F的TLabel。

enter image description here

delphi firemonkey delphi-xe8
3个回答
3
投票

您可以将DisabledOpacity设置为1。

请参阅示例,其中有两个按钮添加到表单:

procedure TForm2.Button2Click(Sender: TObject);
begin
  Button1.DisabledOpacity := 1;
  Button1.Enabled := not Button1.Enabled;
end;

这是受保护的成员,因此您必须覆盖代码中的控件。

 TButton = class(FMX.Stdctrls.TButton)
 //
  end;

  TForm2 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

4
投票

将控件(TRectangle)设置为hittest := false;

它将不再捕获鼠标事件和父控件。对于其他控件,您可以将它与Tabstop:=false结合使用。现在它不会得到关注,因此大多数功能都将被禁用。


0
投票

DisabledOpacity是TControl的私有属性,您可以在FMX.Controls.TControl中找到它。

您可以创建一个自定义类的tcontrol,其中DisabledOpacity是公共的,并将其设置为您的控件(如每个TControl后代):

  TmyC = class(TControl)
  public
    property DisabledOpacity;
  end;

...

  TmyC(Button1).DisabledOpacity := 1;
© www.soinside.com 2019 - 2024. All rights reserved.