好像没有,等下面的人<br><br>procedure TWinControl.AlignControls(AControl: TControl; var Rect: TRect);<br>var<br> AlignList: TList;<br><br> function InsertBefore(C1, C2: TControl; AAlign: TAlign): Boolean;<br> begin<br> Result := False;<br> case AAlign of<br> alTop: Result := C1.Top < C2.Top;<br> alBottom: Result := (C1.Top + C1.Height) >= (C2.Top + C2.Height);<br> alLeft: Result := C1.Left < C2.Left;<br> alRight: Result := (C1.Left + C1.Width) >= (C2.Left + C2.Width);<br> alCustom: Result := CustomAlignInsertBefore(C1, C2);<br> end;<br> end;<br><br> procedure DoPosition(Control: TControl; AAlign: TAlign; AlignInfo: TAlignInfo);<br> var<br> NewLeft, NewTop, NewWidth, NewHeight: Integer;<br> ParentSize: TPoint;<br> begin<br> with Rect do<br> begin<br> if (AAlign = alNone) or (Control.Anchors <> AnchorAlign[AAlign]) then<br> begin<br> with Control do<br> if (FOriginalParentSize.X <> 0) and (FOriginalParentSize.Y <> 0) then<br> begin<br> NewLeft := Left;<br> NewTop := Top;<br> NewWidth := Width;<br> NewHeight := Height;<br> if Parent.HandleAllocated then<br> ParentSize := Parent.ClientRect.BottomRight<br> else<br> ParentSize := Point(Parent.Width, Parent.Height);<br> if akRight in Anchors then<br> if akLeft in Anchors then<br> // The AnchorRules.X is the original width<br> NewWidth := ParentSize.X - (FOriginalParentSize.X - FAnchorRules.X)<br> else<br> // The AnchorRules.X is the original left<br> NewLeft := ParentSize.X - (FOriginalParentSize.X - FAnchorRules.X)<br> else if not (akLeft in Anchors) then<br> // The AnchorRules.X is the original middle of the control<br> NewLeft := MulDiv(FAnchorRules.X, ParentSize.X, FOriginalParentSize.X) -<br> NewWidth div 2;<br> if akBottom in Anchors then<br> if akTop in Anchors then<br> // The AnchorRules.Y is the original height<br> NewHeight := ParentSize.Y - (FOriginalParentSize.Y - FAnchorRules.Y)<br> else<br> // The AnchorRules.Y is the original top<br> NewTop := ParentSize.Y - (FOriginalParentSize.Y - FAnchorRules.Y)<br> else if not (akTop in Anchors) then<br> // The AnchorRules.Y is the original middle of the control<br> NewTop := MulDiv(FAnchorRules.Y, ParentSize.Y, FOriginalParentSize.Y) -<br> NewHeight div 2;<br> FAnchorMove := True;<br> try<br> SetBounds(NewLeft, NewTop, NewWidth, NewHeight);<br> finally<br> FAnchorMove := False;<br> end;<br> end;<br> if AAlign = alNone then Exit;<br> end;<br><br> NewWidth := Right - Left;<br> if (NewWidth < 0) or (AAlign in [alLeft, alRight, alCustom]) then<br> NewWidth := Control.Width;<br> NewHeight := Bottom - Top;<br> if (NewHeight < 0) or (AAlign in [alTop, alBottom, alCustom]) then<br> NewHeight := Control.Height;<br> NewLeft := Left;<br> NewTop := Top;<br> case AAlign of<br> alTop:<br> Inc(Top, NewHeight);<br> alBottom:<br> begin<br> Dec(Bottom, NewHeight);<br> NewTop := Bottom;<br> end;<br> alLeft:<br> Inc(Left, NewWidth);<br> alRight:<br> begin<br> Dec(Right, NewWidth);<br> NewLeft := Right;<br> end;<br> alCustom:<br> begin<br> NewLeft := Control.Left;<br> NewTop := Control.Top;<br> CustomAlignPosition(Control, NewLeft, NewTop, NewWidth,<br> NewHeight, Rect, AlignInfo);<br> end;<br> end;<br> end;<br> Control.FAnchorMove := True;<br> try<br> Control.SetBounds(NewLeft, NewTop, NewWidth, NewHeight);<br> finally<br> Control.FAnchorMove := False;<br> end;<br> { Adjust client rect if control didn't resize as we expected }<br> if (Control.Width <> NewWidth) or (Control.Height <> NewHeight) then<br> with Rect do<br> case AAlign of<br> alTop: Dec(Top, NewHeight - Control.Height);<br> alBottom: Inc(Bottom, NewHeight - Control.Height);<br> alLeft: Dec(Left, NewWidth - Control.Width);<br> alRight: Inc(Right, NewWidth - Control.Width);<br> alClient:<br> begin<br> Inc(Right, NewWidth - Control.Width);<br> Inc(Bottom, NewHeight - Control.Height);<br> end;<br> end;<br> end;<br><br> function Anchored(Align: TAlign; Anchors: TAnchors): Boolean;<br> begin<br> case Align of<br> alLeft: Result := akLeft in Anchors;<br> alTop: Result := akTop in Anchors;<br> alRight: Result := akRight in Anchors;<br> alBottom: Result := akBottom in Anchors;<br> alClient: Result := Anchors = [akLeft, akTop, akRight, akBottom];<br> else<br> Result := False;<br> end;<br> end;<br><br> procedure DoAlign(AAlign: TAlign);<br> var<br> I, J: Integer;<br> Control: TControl;<br> AlignInfo: TAlignInfo;<br> begin<br> AlignList.Clear;<br> if (AControl <> nil) and ((AAlign = alNone) or AControl.Visible or<br> (csDesigning in AControl.ComponentState) and<br> not (csNoDesignVisible in AControl.ControlStyle)) and<br> (AControl.Align = AAlign) then<br> AlignList.Add(AControl);<br> for I := 0 to ControlCount - 1 do<br> begin<br> Control := Controls;<br> if (Control.Align = AAlign) and ((AAlign = alNone) or (Control.Visible or<br> (Control.ControlStyle * [csAcceptsControls, csNoDesignVisible] =<br> [csAcceptsControls, csNoDesignVisible])) or<br> (csDesigning in Control.ComponentState) and<br> not (csNoDesignVisible in Control.ControlStyle)) then<br> begin<br> if Control = AControl then Continue;<br> J := 0;<br> while (J < AlignList.Count) and not InsertBefore(Control,<br> TControl(AlignList[J]), AAlign) do Inc(J);<br> AlignList.Insert(J, Control);<br> end;<br> end;<br> for I := 0 to AlignList.Count - 1 do<br> begin<br> AlignInfo.AlignList := AlignList;<br> AlignInfo.ControlIndex := I;<br> AlignInfo.Align := AAlign;<br> DoPosition(TControl(AlignList), AAlign, AlignInfo);<br> end;<br> end;<br><br> function AlignWork: Boolean;<br> var<br> I: Integer;<br> begin<br> Result := True;<br> for I := ControlCount - 1 downto 0 do<br> if (Controls.Align <> alNone) or<br> (Controls.Anchors <> [akLeft, akTop]) then Exit;<br> Result := False;<br> end;<br><br>begin<br> if FDockSite and FUseDockManager and (FDockManager <> nil) then<br> FDockManager.ResetBounds(False);<br> { D5 VCL Change (ME): Aligned controls that are not dock clients now<br> get realigned. Previously the code below was "else if AlignWork". }<br> if AlignWork then<br> begin<br> AdjustClientRect(Rect);<br> AlignList := TList.Create;<br> try<br> DoAlign(alTop);<br> DoAlign(alBottom);<br> DoAlign(alLeft);<br> DoAlign(alRight);<br> DoAlign(alClient);<br> DoAlign(alCustom);<br> DoAlign(alNone);// Move anchored controls<br> ControlsAligned;<br> finally<br> AlignList.Free;<br> end;<br> end;<br> { Apply any constraints }<br> if Showing then AdjustSize;<br>end;<br><br>procedure TWinControl.AlignControl(AControl: TControl);<br>var<br> Rect: TRect;<br>begin<br> if not HandleAllocated or (csDestroying in ComponentState) then Exit;<br> if FAlignLevel <> 0 then<br> Include(FControlState, csAlignmentNeeded)<br> else<br> begin<br> DisableAlign;<br> try<br> Rect := GetClientRect;<br> AlignControls(AControl, Rect);<br> finally<br> Exclude(FControlState, csAlignmentNeeded);<br> EnableAlign;<br> end;<br> end;<br>end;