How do I restrict my custom control's children to a certain area?

限于喜欢 提交于 2020-02-24 12:09:21

问题


I have a custom control based on TPanel, and it has an inner panel that defines the working region for my components and a outer area with a "minimize/restore" button to hide and show the (inner) panel.

If I drop a component at design time on my control and set its Align property to alClient, the size of the outer panel is used and the minimize button is no longer visible.

How can I align or drop components on my panel to force them (to stay) within the area of the inner panel?


回答1:


Place the button on an own panel which will not accept other controls and keep it in front, but would have the disadvantage that other controls could be covered.

procedure THidePanel.AdjustClientRect(var Rect: TRect);
begin
  inherited;
  FPanel.BringToFront;
end;

constructor THidePanel.create(AOwner: TComponent);
begin
  inherited;
  FPanel := TPanel.Create(self);
  FPanel.Align := alright;
  FPanel.Parent := self;
  FPanel.BevelOuter := bvNone;
  FPanel.Width := 30;
  FButton:=TSpeedButton.Create(self);
  FButton.Parent := FPanel;
  FPanel.ControlStyle := FPanel.ControlStyle - [csAcceptsControls];
end;


来源:https://stackoverflow.com/questions/15924468/how-do-i-restrict-my-custom-controls-children-to-a-certain-area

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!