Delphi 中框架和表单的动态调整大小

发布于 2024-07-17 20:11:45 字数 1660 浏览 5 评论 0原文

我有一个 TFrame 后代,上面有一个相当大的面板,它是第三方组件 (TLMDSimplePanel))。 该面板上的大小调整效果很好,但我希望当用户更改面板大小时,它所包含的框架能够动态调整大小。 (该面板上有一个小的调整拇指大小的手柄,用户只需单击并用鼠标拖动即可)。

该框架的代码如下:

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.

如果用户缩小框架的大小,它的工作效果非常好,但是如果他们尝试将其拉伸到大于其原始边界,则只能将其扩展到看起来是其原始大小 + ExpandByPixels,之后用户无法继续流畅地将其拖动到更大的尺寸。

如果他们停下来,然后再次单击并拖动尺寸夹点,他们可以将其拖出到更大的尺寸,但同样会受到相同方式的约束(当前尺寸 + ExpandByPixels = 外部边界)。 他们可以无休止地重复这个循环,将框架扩展到任何尺寸,但不能通过一次鼠标移动流畅地进行,而这正是我想要的。

我也针对 TForm 后代测试了同样的问题,并得到了相同的症状。

我在这里缺少什么?

预先感谢您的任何和所有帮助。 :-)

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. :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

再浓的妆也掩不了殇 2024-07-24 20:11:45

您是否尝试过将 Frame.Autosize 设置为 true?
或者您需要在鼠标移动时调整框架的大小。 这样所包含的对象就可以在保持在容器边界内的同时扩展。

更新:一些简单的代码,可与常规 TPanel 一起使用以水平调整大小......

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文