2

ユーザーがパネルを最小化し、このパネルのコンポーネントを非表示にできるパネル コントロールを作成しています。1 つの THidePanel は期待どおりに機能するようですが、スプリッターで区切られたフォームに 2 つ配置すると機能しません。最初のパネルはalLeftに揃えられます。2 番目のパネルalClient :

スクリーンダンプ

2 番目のパネルのボタンをクリックしても、最小化または最大化に反応しません。これが私のコードのすべてです。うまくいかないのはなぜですか?

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;
4

2 に答える 2