首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >THidepanel @ runtime

THidepanel @ runtime
EN

Stack Overflow用户
提问于 2013-04-09 22:19:23
回答 1查看 136关注 0票数 0

我已经在这里找到了很多关于编写允许隐藏组件的组件的帮助( THIDEPANEL。现在我遇到了第一个问题:

在这个类的OnCreate事件中,我获取了面板的宽度和高度,我希望在隐藏/取消隐藏面板的同时恢复为原始值。实际上,隐藏过程总是减小面板的大小

代码语言:javascript
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-10 05:38:53

这是因为FLargeWidth私有字段的值无效。您在构造函数期间将其与Self.Width一起分配(并且您可能永远不会更新它)。这不是您在设计时或运行时设置的宽度,而是来自TCustomPanel.Create的硬编码宽度,即185。请注意,当控件的构造函数运行时,控件尚未放置。

如果你想记住设置的宽度,那么你应该“覆盖TControl.SetWidth”。但由于该方法是私有的(而不是虚拟的),您需要重写SetBoundsResize以响应Width的更改。我会选择后者,可能需要附加一个条件:

代码语言:javascript
复制
procedure THidePanel.Resize;
begin
  if not HasCustomWidth then  //< Replace this with your own logic condition
    FLargeWidth := Width;
  inherited Resize;
end;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15904486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档