views:

1324

answers:

1

I have a TFrame descendent that has on it a sizable panel which is a third-party component (TLMDSimplePanel)). The sizing on that panel works great, but I want the frame it is contained in to resize dynamically when the user changes the size of the panel. (The panel has a little sizing thumb grip on it that the user can just click and drag with the mouse).

The code for this frame is below:

unit SizeableFrame;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TcmBaseFrameFrame, LMDCustomControl, LMDCustomPanel, LMDCustomBevelPanel,
  LMDSimplePanel, StdCtrls;

type
  TcmSizeableFrame = class(TcmBaseFrame)
    LMDSimplePanel1: TLMDSimplePanel;
    Memo1: TMemo;
    Memo2: TMemo;
    procedure LMDSimplePanel1Resize(Sender: TObject);
    procedure FrameCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
      var Resize: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  cmSizeableFrame: TcmSizeableFrame;

implementation

{$R *.dfm}

procedure TcmSizeableFrame.FrameCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin
  inherited;
  Resize := True;
end;

procedure TcmSizeableFrame.LMDSimplePanel1Resize(Sender: TObject);
const
  ExpandByPixels = 60;
var
  MyFrame : TFrame;        
begin
  inherited;
  Self.Height := LMDSimplePanel1.Height + ExpandByPixels;
  Self.Width := LMDSimplePanel1.Width  +  ExpandByPixels;
end;

end.

It works wonderfully, if the user is shrinking the the size of the frame, but if they try to stretch it larger than its original bounds, they can only expand it to what appears to be its original size + ExpandByPixels, after which the user cannot continue to fluidly drag it to a larger size.

If they stop, and then click and drag the size grip again, they can then drag it out to a larger size, but again this is constrained in the same way (current size + ExpandByPixels = the outer bound). They can repeat this cycle endlessly, expanding the frame to any size, but not fluidly in one mouse movement, which is what I want.

I have tested this same problem against TForm descendents as well, and get the same symptoms.

What am I missing here?

Thanks in advance for any and all help. :-)

+1  A: 

Have you tried to set the Frame.Autosize to true?
Or you would need to resize the frame when the mouse moves. So that the contained object could expand while staying within the boundaries of the container.

Update: some simple code that works with a regular TPanel to resize horizontally...

type
  TFrame5 = class(TFrame)
    Panel1: TPanel;
    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Panel1Resize(Sender: TObject);
  end;

implementation

{$R *.dfm}

procedure TFrame5.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  with Sender as TPanel do
  if ssLeft in Shift then
  begin
    Width := X;
  end;
end;

procedure TFrame5.Panel1Resize(Sender: TObject);
begin
  with Sender as TPanel do
  begin
    (Parent as TFrame).Width := Width + 2*Left;
  end;
end;
François
Yes, I did try that. What I found was that while the panel was sizing, the autosize functionality of the frame would not kick in (maybe it was waiting until the panel resize was complete), so it did not work. Additionally, though, I need a "buffer border" around the panel; not flush against it.
Jamo
Try with my sample code, it works with a regular TPanel. You might have to modify your TLMDSimplePanel component though.
François
Additionally for the "buffer border", you can play with the padding property of the Frame or the Margins of the Panel...
François
Agreed. Padding is a *much* better way to do buffers around controls than surrounding it with other controls as spacers. That can get real ugly real fast.
Mason Wheeler