Position of controls on a bevelled panel

For some time now I have been struggling with the file control behavior with settings Align

or Anchors

(like here ). This time, I was working with one block until I noticed that the top position of the buttons had moved from the original 10 to about -50, so I tried to figure out what was the reason.

If I use panel with BevelKind = bkFlat

and controls with Anchors = [akRight, akBottom]

, then the position of all controls will be scaled down according to the settings. As shown in the following example, Left

navigates with Anchors = [akRight]

and Top

with Anchors = [akBottom]

. Always the width of the bevels that the panel has set, in this case -4 in both directions. After starting the program or reopening the next device, the position moves from (150, 10)

to (146, 6)

and will continue indefinitely after opening and saving the device.

So, I would like to know what is responsible for recalculating the positions of all components after opening the device and saving to file dfm

, if it can be fixed.

enter image description here

enter image description here

enter image description here

PMain.pas

unit PMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Grids;

type
  TUMain = class(TForm)
    pnl1: TPanel;
    btn1: TButton;
  end;

var
  UMain: TUMain;

implementation

{$R *.dfm}

end.

      

PMain.dfm

object UMain: TUMain
  Left = 0
  Top = 0
  Caption = 'UMain'
  ClientHeight = 50
  ClientWidth = 250
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object pnl1: TPanel
    Left = 0
    Top = 0
    Width = 250
    Height = 50
    Align = alClient
    BevelKind = bkFlat
    Caption = 'pnl1'
    TabOrder = 0
    DesignSize = (
      246
      46)
    object btn1: TButton
      Left = 150
      Top = 10
      Width = 75
      Height = 25
      Anchors = [akRight, akBottom]
      Caption = 'btn1'
      TabOrder = 0
    end
  end
end

      

+3


source to share


1 answer


This seems to be a bug in Delphi. I repeated the same behavior using your code in Delphi 10 Seattle.

The only thing you can really do is not set these specific bevels at design time. Set this at runtime instead ...

pnl1.BevelKind := bkFlat; 

      



Most likely, without digging into the controls, the order in which the properties are passed from the DFM is in the correct (or wrong) order up to the point where perhaps the button is positioned before which the panel should be sized, for example. I can't imagine what fix you could make without completely rebuilding the VCL, which is out of the question.

You should send a QC report to Embarcadero if no one has reported this issue yet.

+2


source







All Articles