gpt4 book ai didi

delphi - 为什么我的尺寸更改控件在与 TSplitter 共享窗体时不起作用?

转载 作者:行者123 更新时间:2023-12-02 09:02:42 25 4
gpt4 key购买 nike

我正在编写一个面板控件,允许用户最小化面板并隐藏该面板上的组件。单个 THidePanel 似乎可以按预期工作,但当我将其中两个放在由拆分器分隔的表单上时,则不然。第一个面板对齐 alLeft;第二个面板alClient:

screen dump

当单击第二个面板的按钮时,它不会做出最小化或最大化的 react 。这是我的全部代码。为什么不起作用?

const
BoarderSize = 20;

type

TButtonPosition = (topleft, topright, buttomleft, buttomright);

///
/// a panel with a smaller panel inside and a button on the side
///
THidePanel = class(TPanel)
private
{ Private-Deklarationen }
///
/// a smaller working panel
WorkingPanel: TPanel;
FLargeHight: Integer;
FLargeWidth: Integer;
FActivateButton: TButton;
FExpandState: Boolean;
FButtonPosition: TButtonPosition;
FOnActivateBtnClick: TNotifyEvent;
procedure SetButtonPosition(const Value: TButtonPosition);
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
constructor create(aOwner: TComponent); override;
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
procedure HideComponents;
procedure H_ActivateButtonClick(Sender: TObject);
procedure SetState(astate: Boolean);
procedure free;
destructor destroy; override;
published
{ Published-Deklarationen }
property OnActivateButtonClick: TNotifyEvent read FOnActivateBtnClick
write FOnActivateBtnClick;
property ButtonPosition: TButtonPosition read FButtonPosition
write SetButtonPosition;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [THidePanel]);
end;

{ THidePanel }

constructor THidePanel.create(aOwner: TComponent);
begin
inherited;
WorkingPanel := TPanel.create(self);
WorkingPanel.Caption := 'V01';
FActivateButton := TButton.create(self);
FActivateButton.Parent := self;
FActivateButton.Caption := '<';
FActivateButton.OnClick := H_ActivateButtonClick;
FActivateButton.Width := BoarderSize;
FActivateButton.Height := BoarderSize;
WorkingPanel.Caption := '';
FLargeWidth := self.Width;
SetButtonPosition(topright);
end;

destructor THidePanel.destroy;
begin
inherited;
end;

procedure THidePanel.free;
begin
inherited;
WorkingPanel.free;
FActivateButton.free;
end;

procedure THidePanel.HideComponents;
var
i: Integer;
begin
for i := 0 to WorkingPanel.ControlCount - 1 do
WorkingPanel.Controls[i].Visible := False;
end;

procedure THidePanel.WMSize(var Msg: TWMSize);
begin
/// set inner panel size
WorkingPanel.Top := self.Top + BoarderSize;
WorkingPanel.Left := self.Left + BoarderSize;
WorkingPanel.Width := self.Width - 2 * BoarderSize;
WorkingPanel.Height := self.Height - 2 * BoarderSize;

/// move button
SetButtonPosition(FButtonPosition);
end;

procedure THidePanel.H_ActivateButtonClick(Sender: TObject);
begin
/// button is clicked!
///
FExpandState := not FExpandState;
SetState( FExpandState );

///
if (Assigned(FOnActivateBtnClick)) then
FOnActivateBtnClick(self);
end;

procedure THidePanel.SetButtonPosition(const Value: TButtonPosition);
begin
FButtonPosition := Value;

case FButtonPosition of
topleft:
begin
FActivateButton.Left := 0;
FActivateButton.Top := 0;
end;

topright:
begin
FActivateButton.Left := self.Width - BoarderSize;
FActivateButton.Top := 0;
end;

buttomleft:
begin
FActivateButton.Left := 0;
FActivateButton.Top := self.ClientWidth - BoarderSize;
end;

buttomright:
begin
FActivateButton.Top := self.ClientWidth - BoarderSize;
FActivateButton.Left := self.Width - BoarderSize;
end;

else
/// never go here

end;
end;

procedure THidePanel.SetState(astate: Boolean);
begin
if astate then
begin
/// ...
FActivateButton.Caption := '>';
self.Width := BoarderSize;
end
else
begin
/// ...
FActivateButton.Caption := '<';
self.Width := FLargeWidth;
end;
end;

最佳答案

当 Control 的 Anchors 设置为 alClient 时,您无法更改大小。
将第二个面板对齐设置为 alLeftalRight 。如果您想使用此控件填充表单,请设置表单的AutoSize True 或在调整大小时手动设置控件的最大尺寸。

关于delphi - 为什么我的尺寸更改控件在与 TSplitter 共享窗体时不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15856305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com