我已经在这里找到了很多关于编写允许隐藏组件的组件的帮助( THIDEPANEL。现在我遇到了第一个问题:
在这个类的OnCreate事件中,我获取了面板的宽度和高度,我希望在隐藏/取消隐藏面板的同时恢复为原始值。实际上,隐藏过程总是减小面板的大小
constructor THidePanel.Create(AOwner: TComponent);
begin
inherited;
// The inner panel
WorkingPanel := TPanel.Create(Self);
WorkingPanel.Caption := '***';
// The hide unhide
FActivateButton := TButton.Create(Self);
FActivateButton.Parent := self;
FActivateButton.Caption := '<';
FActivateButton.OnClick := H_ActivateButtonClick;
FActivateButton.Width := BoarderSize;
FActivateButton.Height := BoarderSize;
WorkingPanel.Caption := '';
// Grab the size of the hide panel, later restore to this values
FLargeWidth := Self.Width;
FLargeHeight := Self.Height;
SetButtonPosition(TopRight);
end;发布于 2013-04-10 05:38:53
这是因为FLargeWidth私有字段的值无效。您在构造函数期间将其与Self.Width一起分配(并且您可能永远不会更新它)。这不是您在设计时或运行时设置的宽度,而是来自TCustomPanel.Create的硬编码宽度,即185。请注意,当控件的构造函数运行时,控件尚未放置。
如果你想记住设置的宽度,那么你应该“覆盖TControl.SetWidth”。但由于该方法是私有的(而不是虚拟的),您需要重写SetBounds或Resize以响应Width的更改。我会选择后者,可能需要附加一个条件:
procedure THidePanel.Resize;
begin
if not HasCustomWidth then //< Replace this with your own logic condition
FLargeWidth := Width;
inherited Resize;
end;https://stackoverflow.com/questions/15904486
复制相似问题