【问题标题】:Delphi Form Height Width Changing in .DFM file on different developer machinesDelphi Form Height Width Changes in .DFM file on different developer machine
【发布时间】:2017-06-15 14:49:24
【问题描述】:

我们有两台不同的开发机器使用同一个 .pas 文件
任何时候开发人员更改表单上的某些内容,.dfm 文件中的 form.width 都可以更改
在一台机器上,Form (width = 651) 和 (ClientWidth = 635)
另一台机器 Form (width = 643) 和 (ClientWidth = 635)

我想知道为什么 .dfm 文件中的(宽度和高度)会发生变化

我想在运行时查看 Calculations 的细分 + 原因之间的差异
(ClientHeight 和 Height) 和 (ClientWidth 和 Width)

所以如果 (width = 651) 和 (ClientWidth = 635)
我如何在运行时检查 Windows 边框宽度或任何我需要锻炼这些值之间的差异?

【问题讨论】:

  • 你有什么问题?
  • 我想看看宽度和客户端宽度之间差异的实际值是多少。例如边框大小等
  • 仅此而已?你不是已经在做那个数学了吗? WidthDiff := Width - ClientWidth; HeightDiff := Height - ClientHeight; 或者您是否也在计算窗口标题区域的非客户端高度?
  • 问题是,在两台不同的机器上,边框大小可能不同,所以我想看看机器 1 上的边框宽度是 8,机器 2 上的边框宽度是 7,所以我知道为什么两台不同机器上的宽度是有区别的
  • 以上数学还不够吗?您需要做的就是将其除以二。同样,您是否需要知道非客户区维度?因为那是你应该说的另一个话题。就目前而言,您的问题是要求一个非常基本的数学问题。我建议从您关于“计算差异”的问题中删除任何内容,而是询问表单的非客户区域。

标签: forms delphi height width


【解决方案1】:

.DFM 文件更改的原因是因为两台机器之间的 Windows 注册表设置存在一些差异
计算机\HKEY_CURRENT_USER\控制面板\桌面\WindowMetrics
这导致边框、标题、表单标题高度/宽度不同

如果您使用相同的 exe 运行以下函数,您可能会得到不同的结果

高度计算
//这将获取表单标题高度
GetSystemMetrics( SM_CYCAPTION )
//这将获取表单边框宽度
GetSystemMetrics(SM_CYFRAME)
//这将获取表单主菜单高度
GetSystemMetrics(SM_CYMENU)

这是一个示例函数,用于显示高度计算的分解

function CalcHeightDifference : String;
  var iActualHeightDifference : integer;
      iCalcHeightDifference : integer;
      sInfo : String;
begin
  iCalcHeightDifference := 0;
  iActualHeightDifference := self.Height - Self.ClientHeight;

  //Caption
  iCalcHeightDifference := iCalcHeightDifference + GetSystemMetrics( SM_CYCAPTION );
  sInfo := ' + Form Caption = ' + inttostr( GetSystemMetrics( SM_CYCAPTION ) );

  //Borders
  iCalcHeightDifference := iCalcHeightDifference + GetSystemMetrics( SM_CYFRAME) + GetSystemMetrics( SM_CYFRAME);
  sInfo := sInfo + sLineBreak + ' + Border Height(' + inttostr( GetSystemMetrics( SM_CYFRAME)) + ') times two = ' + inttostr( GetSystemMetrics( SM_CYFRAME)+GetSystemMetrics( SM_CYFRAME)  );

  //Menu
  if self.Menu <> nil then begin
    iCalcHeightDifference := iCalcHeightDifference + GetSystemMetrics(SM_CYMENU);
    sInfo := sInfo + sLineBreak + ' + Form MainMenu = ' + inttostr( GetSystemMetrics(SM_CYMENU) );
  end;

  result := format( 'Form.ClientHeight=%d', [Self.ClientHeight])
          + sLineBreak
          + format('Form.Height=%d', [Self.Height])
          + sLineBreak
          + format('The Height Difference of %d is made up of', [Self.Height-Self.ClientHeight])
          + sLineBreak
          + sInfo
          + sLineBreak
          + format(' Total( %d )', [iCalcHeightDifference])     ;
end;

宽度计算
//这将获取表单边框宽度
GetSystemMetrics(SM_CXFRAME)

这是一个示例函数,用于显示宽度计算的分解

function CalcWidthDifference : String;
  var iActualWidthDifference : integer;
    iCalcWidthDifference : integer;
    sInfo : String;
begin
  iCalcWidthDifference := 0;
  iActualWidthDifference := self.Width - Self.ClientWidth;

  //Borders
  iCalcWidthDifference := GetSystemMetrics( SM_CXFRAME) + GetSystemMetrics( SM_CXFRAME);
  sInfo := ' + Border Width(' + inttostr( GetSystemMetrics( SM_CXFRAME) ) + ') times Two = ' + inttostr( GetSystemMetrics( SM_CXFRAME)+GetSystemMetrics( SM_CXFRAME) );

  result := format( 'Form.ClientWidth=%d', [Self.ClientWidth])
          + sLineBreak
          + format('Form.Width=%d', [Self.Width])
          + sLineBreak
          + format('The Width Difference of %d is made up of', [Self.Width-Self.ClientWidth])
          + sLineBreak
          + sInfo
          + sLineBreak
          + format(' Total( %d )', [iCalcWidthDifference])    ;
end;

这一切都是因为我们有两台 Windows 开发机器,它们随机更改表单和面板等上 .DFM 文件的宽度
我在下面包含了一些从不同机器上的相同 exe 运行的屏幕截图,以显示宽度不同。如果我要在设计时更改该表单上的某些内容,.dfm 文件将以不同的宽度保存

机器 1 机2

【讨论】:

  • 这就是答案?
  • 我已经编辑了答案,现在更有意义了吗?如果它对任何人都没有用,我可以删除这个问题,只是认为它可能会帮助遇到同样问题的其他人
猜你喜欢
  • 1970-01-01
  • 2012-10-28
  • 2011-04-23
  • 2022-12-27
  • 1970-01-01
  • 2022-12-02
  • 1970-01-01
  • 1970-01-01
  • 2022-12-01
相关资源
最近更新 更多