如果(在Delphi中)我这样做
Panel1.ManualFloat(Rect(500,500,600,600));
Run Code Online (Sandbox Code Playgroud)
面板不是浮动在指定的Rect位置,而是浮动在某种窗口的默认位置.如何让面板(或其他控件)浮动到指定位置.但它似乎确实具有正确的形状.我需要设置一些其他属性才能使其正常工作吗?
编辑:只是为了清楚.我希望上面的代码使得面板相对于屏幕的左上角位于(500x500)的100x100正方形,而不是.形状是正确的,但位置不正确.如果后续控件浮动,则它们在屏幕上级联.
编辑2:这在Delphi 7中似乎不是问题,但在Delphi 2007中通过XE2(可能更早)
不要再看了:它是VCL中的一个错误.
ManualFloat创建一个浮动窗口,并设置它Top,Left价值观TControl.CreateFloatingDockSite(Bounds: TRect),后来将其ClientWidth.
这是一个错误,因为这样做会强制WindowHandle创建(它还没有Handle)
function TCustomForm.GetClientRect: TRect;
begin
if IsIconic(Handle) then // <===
Run Code Online (Sandbox Code Playgroud)
并调用窗口的默认定位(级联yadda yadda ...)重置Top和Left
此修复程序会设置ClientWidth和ClientHeight设置之前Top和Left在性能TControl.CreateFloatingDockSite(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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
893 次 |
| 最近记录: |