如何阻止IDE在设计时向TContent添加TGrabHandle.TGrabHandleRectangle
解决Delphi FireMonkey TContent设计时自动添加TGrabHandle的问题
最彻底的方案是自定义TContent的子类,重写设计时添加抓取手柄的方法,阻止其创建:
1. 创建自定义TContent组件
继承原生TContent,重写AddGrabHandle方法,仅在非设计模式下执行父类逻辑:
unit MyCustomContent; interface uses FMX.Controls, FMX.Types; type TMyCustomContent = class(TContent) protected procedure AddGrabHandle; override; end; implementation procedure TMyCustomContent.AddGrabHandle; begin // 仅运行时添加抓取手柄,设计模式下跳过 if not (csDesigning in ComponentState) then inherited; end; end.
2. 注册自定义组件
在组件包的注册单元中注册这个自定义组件,方便IDE中调用:
unit MyComponentsRegistration; interface uses Classes, MyCustomContent; procedure Register; implementation procedure Register; begin RegisterComponents('FireMonkey Custom', [TMyCustomContent]); end; end.
编译并安装这个组件包后,在IDE的组件面板中选择TMyCustomContent代替原生TContent使用,设计时就不会自动生成TGrabHandle了。
临时替代方案(无需自定义组件)
如果不想自定义组件,可以在表单的OnCreate事件中手动移除设计时生成的TGrabHandle,但这种方法每次打开表单都会执行,且IDE在某些操作后可能重新生成:
procedure TMainForm.FormCreate(Sender: TObject); var I: Integer; begin if csDesigning in ComponentState then begin // 反向遍历组件列表,避免索引错乱 for I := Content1.ComponentCount - 1 downto 0 do begin if Content1.Components[I] is TGrabHandle then Content1.Components[I].Free; end; end; end;
注意:修改VCL/FMX源码来禁用该行为不推荐,会影响后续Delphi版本的升级兼容性。
内容的提问来源于stack exchange,提问作者zeus
相关产品推荐
相关产品推荐

