Delphi:ButtonedEdit +框架=错误

发布于 2024-11-28 18:00:54 字数 295 浏览 1 评论 0原文

Delphi XE。

有一个按钮编辑(带有左侧按钮),一个带有按钮图片的图像列表。一切都在框架上(如果在表格上也可以)。

按钮在设计时没有缩进,但在运行时却有。

这是一个错误吗?

在此处输入图像描述 在此处输入图像描述

谢谢!

Delphi XE.

There is a Buttoned Edit (with the left button), an image list with a picture for the button. All is on a frame (it is Ok if on a form).

There is no an indent of the button in a design time, but it is in a run time.

Is it a bug?

enter image description here
enter image description here

Thanks!

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

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

发布评论

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

评论(1

单身情人 2024-12-05 18:00:54

是的,这是一个错误。由于某种原因,当编辑驻留在框架中时,TButtonEditCtl3D 属性无法从 .dfm 文件中正确流式传输。流式传输导致 Ctl3DFalse 而不是 True

然后,在 TEditButton.UpdateBounds 中执行以下代码:

if (not FEditControl.Ctl3D) and (FEditControl.BorderStyle <> bsNone) then
begin
  FGlyph.Top := 2;
  Inc(NewLeft, 2);
end;

这就是将按钮的位置向右和向下移动 2 个像素。

您可以通过在代码中手动设置 Ctl3D 并强制再次调用 UpdateBounds 来解决该错误。我使用插入器完成了此操作:

type
  TButtonedEdit = class(ExtCtrls.TButtonedEdit)
  protected
    procedure Loaded; override;
  end;

procedure TButtonedEdit.Loaded;
begin
  inherited;
  Ctl3D := True;
  LeftButton.Visible := not LeftButton.Visible;
  LeftButton.Visible := not LeftButton.Visible;
  RightButton.Visible := not RightButton.Visible;
  RightButton.Visible := not RightButton.Visible;
end;

您可以将其包含在框架中,但请确保插入的 TButtonedEdit 的声明位于声明框架之前。或者,如果错误影响许多框架,请以通用单位声明它,并使用 ExtCtrls 后在框架中使用该单位。

现在,对于为什么流不能正确设置 Ctl3D 的明显问题,我没有答案。也许比我更了解表单流的人可以启发我们!

Yes it's a bug. For some reason the Ctl3D property of the TButtonEdit is not being streamed correctly from the .dfm file when the edit resides in a frame. The streaming is resulting in Ctl3D being False instead of True.

Then, in TEditButton.UpdateBounds the following code executes:

if (not FEditControl.Ctl3D) and (FEditControl.BorderStyle <> bsNone) then
begin
  FGlyph.Top := 2;
  Inc(NewLeft, 2);
end;

This is what is shifting the position of your button 2 pixels right and down.

You can work around the bug by manually setting Ctl3D in code and forcing UpdateBounds to be called again. I did this with an interposer:

type
  TButtonedEdit = class(ExtCtrls.TButtonedEdit)
  protected
    procedure Loaded; override;
  end;

procedure TButtonedEdit.Loaded;
begin
  inherited;
  Ctl3D := True;
  LeftButton.Visible := not LeftButton.Visible;
  LeftButton.Visible := not LeftButton.Visible;
  RightButton.Visible := not RightButton.Visible;
  RightButton.Visible := not RightButton.Visible;
end;

You can include this in your frame, but make sure that the declaration of the interposed TButtonedEdit is before your frame is declared. Or if the bug afflicts many frames, declare it in a common unit and use that unit in your frame after you use ExtCtrls.

Now, as for the obvious question as to why the streaming doesn't set Ctl3D correctly, I have no answer for that. Perhaps someone more knowledgeable than I am about form streaming could enlighten us!

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