delphi – ManualFloat没有使用指定的Rect
如果(在Delphi中)我这样做
Panel1.ManualFloat(Rect(500,500,600,600)); 面板不是浮动在指定的Rect位置,而是浮动在某种窗口的默认位置.如何让面板(或其他控件)浮动到指定位置.但它确实具有正确的形状.我需要设置一些其他属性才能使其正常工作吗? 编辑:只是为了清楚.我希望上面的代码使面板相对于屏幕的左上角位于(500×500)的100×100正方形,但事实并非如此.形状是正确的,但位置不正确.如果后续控件浮动,则它们在屏幕上级联. 编辑2:这在Delphi 7中似乎不是问题,但在Delphi 2007中通过XE2(可能更早) 解决方法
不要再看了:它是VCL中的一个错误.
ManualFloat创建一个浮动窗口并在TControl.CreateFloatingDockSite(Bounds:TRect)中设置其Top,Left值,然后设置其ClientWidth. 这是一个错误,因为这样做会强制WindowHandle创建(它还没有Handle) function TCustomForm.GetClientRect: TRect; begin if IsIconic(Handle) then // <=== 并调用Window的默认定位(级联yadda yadda …)重置Top和Left 修复方法是在TControl.CreateFloatingDockSite中设置Top和Left属性之前设置ClientWidth和ClientHeight(Bounds:TRect) 更新:Controls.pas中的固定代码 function TControl.CreateFloatingDockSite(Bounds: TRect): TWinControl; begin Result := nil; if (FloatingDockSiteClass <> nil) and (FloatingDockSiteClass <> TWinControlClass(ClassType)) then begin Result := FloatingDockSiteClass.Create(Application); with Bounds do begin // Setting Client area can create the window handle and reset Top and Left Result.ClientWidth := Right - Left; Result.ClientHeight := Bottom - Top; // It is now safe to position the window where asked Result.Top := Top; Result.Left := Left; end; end; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |