Ros*_*erg 14 delphi delphi-7 delphi-2010 delphi-xe
我用Devexpress为我的软件设置了皮肤,我发现标签是不透明的,导致它们具有灰色背景.
只有无穷无尽的形式,所以我想知道是否有办法自动完成这项任务(将标签设置为透明).
我之前做了类似的事情,表单上的Devexpress控件有LookAndFeel.NativeStyle = True,我在所有dfm表单上使用Grep Search将其替换为False.但是,在标签的情况下,透明属性不存在.
谢谢.
NGL*_*GLN 15
全局Screen
变量跟踪所有形式:
procedure MakeLabelsTransparent(AParent: TWinControl);
var
I: Integer;
begin
with AParent do
for I := 0 to ControlCount - 1 do
if Controls[I] is TLabel then
TLabel(Controls[I]).Transparent := True
else if Controls[I] is TWinControl then
MakeLabelsTransparent(TWinControl(Controls[I]));
end;
procedure TMainForm.ActiveFormChange(Sender: TObject);
begin
with Screen do
if (ActiveCustomForm <> nil) and (ActiveCustomForm.Tag = 0) then
begin
MakeLabelsTransparent(ActiveCustomForm);
ActiveCustomForm.Tag := 1;
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
Screen.OnActiveFormChange := ActiveFormChange;
end;
Run Code Online (Sandbox Code Playgroud)
如果你必须为特定表单使用Tag属性,那么省略这个检查:它实际上不会那么慢.
对于此类任务,GExperts包含" 设置组件属性"工具:
此工具在后台等待,直到您编译项目.然后,它扫描当前项目的表单以检查具有某些属性的组件,并将这些属性更改为定义的值.在编译应用程序之前,此工具对于停用数据集或数据库连接很有用,但它也可用于任何类似的情况.要激活扫描,请在GExperts Configuration(GExperts配置)屏幕中启用此专家旁边的复选框.
它可用于设置尚未包含在DFM中的属性,并且只需要在GExpert配置中添加一个附加条目,并进行重新编译.
我刚刚测试了它,它按预期工作.
在设计时,您可以解析所有.dfm然后添加
Transparent = True
Run Code Online (Sandbox Code Playgroud)
在任何之后排队
object MyLabel : TLabel
Run Code Online (Sandbox Code Playgroud)
线.
在运行时,您可以覆盖TCustomForm.DoCreate
和TCustomFrame.Create
方法,如下所示:
type
THookedForm = class(TCustomForm)
procedure HookedDoCreate;
end;
THookedFrame = class(TCustomFrame)
constructor Create(AOwner: TComponent); override;
end;
var
PatchForm, OriginalForm: TPatchEvent;
PatchPositionForm: PPatchEvent = nil;
PatchFrame, OriginalFrame: TPatchEvent;
PatchPositionFrame: PPatchEvent = nil;
procedure PatchCreate;
var ov: cardinal;
begin
// hook TForm:
PatchPositionForm := PPatchEvent(@THookedForm.DoCreate);
OriginalForm := PatchPositionForm^;
PatchForm.Jump := $E9; // Jmp opcode
PatchForm.Offset := PtrInt(@THookedForm.HookedDoCreate)-PtrInt(PatchPositionForm)-5;
if not VirtualProtect(PatchPositionForm, 5, PAGE_EXECUTE_READWRITE, @ov) then
RaiseLastOSError;
PatchPositionForm^ := PatchForm; // enable Hook
// hook TFrame:
PatchPositionFrame := PPatchEvent(@TCustomFrame.Create);
OriginalFrame := PatchPositionFrame^;
PatchFrame.Jump := $E9; // Jmp opcode
PatchFrame.Offset := PtrInt(@THookedFrame.Create)-PtrInt(PatchPositionFrame)-5;
if not VirtualProtect(PatchPositionFrame, 5, PAGE_EXECUTE_READWRITE, @ov) then
RaiseLastOSError;
PatchPositionFrame^ := PatchFrame; // enable Hook
end;
{ THookedForm }
procedure THookedForm.HookedDoCreate;
var i: integer;
begin
// enumerate all labels, then set Transparent := true
for i := 0 to Components.Count-1 do
if Components[i] is TLabel then
TLabel(Components[i]).Transparent := true;
DoCreate; // call initial code
end;
{ THookedFrame }
constructor THookedFrame.Create(AOwner: TComponent);
var i: integer;
begin
// enumerate all labels, then set Transparent := true
for i := 0 to Components.Count-1 do
if Components[i] is TLabel then
TLabel(Components[i]).Transparent := true;
inherited Create(AOwner); // call normal constructor
end;
....
initialization
PatchCreate;
Run Code Online (Sandbox Code Playgroud)
一个相关的提示(我总是忘记使用这个方便的功能):
Component/Create component template
;从那时起,模板在工具选项板中显示为新的组件类型,具有您喜欢的设置.
(是的,我知道这不会改变当前的标签)
归档时间: |
|
查看次数: |
1783 次 |
最近记录: |