有没有办法关闭 TDBRadioGroup 上的字幕

Is there a way to turn off the Caption on a TDBRadioGroup

我有一个 TDBRadioGroup 已添加到我的表单中。

我真的很想把标题放在它的左边而不是在上面(表格有点大而且有点高,我想把它挤进去)。

我可以在广播组的左侧添加自己的标签。但是控件坚持要保留 space 一个不存在的 Caption。有什么办法可以完全关闭它吗?

到目前为止我们想出的最好办法是将其粘贴在 TPanel 上,然后隐藏顶部的几行 off-panel.

A TGroupBox(及其后代 TDBGroupBox)基本上是 Windows GroupBox 的包装器。该控件旨在在 upper-left 角显示 user-defined 标签,并且没有任何样式设置可将其删除。

因此,除了创建自己的控件来托管一系列 TRadioButton 控件并自己显示它们之外,没有 built-in 方法来禁用为标题保留的 space。当然,您可以通过设置 Caption := '' 来隐藏文本,但不会仅仅因为未显示标题而删除文本下行部分的填充。

您可以覆盖 TRadioGroup 的绘制过程,以便将框架绘制得更靠近项目列表的顶部。您可以创建类型为 TNoCaptionRadioGroup 的新组件。您可能仍然需要使用您尝试过的面板技巧,但通过降低框架的顶部,您可以抓住 non-existent 标题消耗的 space。像这样:

tNoCaptionRadioBox = class(TRadioGroup)
protected
procedure paint; override;
end;

procedure tNoCaptionRadioBox.paint;
var
H: Integer;
R: TRect;
begin
with Canvas do
begin
  Font := Self.Font;
  H := TextHeight('0');
  R := Rect(0, H, Width, Height);
  if Ctl3D then
  begin
    Inc(R.Left);
    Inc(R.Top);
    Brush.Color := clBtnHighlight;
    FrameRect(R);
    OffsetRect(R, -1, -1);
    Brush.Color := clBtnShadow;
  end else
    Brush.Color := clWindowFrame;
  FrameRect(R);
  end;
end;

这取自绘制 TCustomGroupBox 的代码。我删除了绘制标题的代码,并将框架的顶部更改为字体的全高。您的实际带标题单选按钮仍将绘制在 Windows 希望它们所在的位置并使用默认间距。

记得用运行包安装工具注册新组件。

procedure Register;
begin
RegisterComponents('myComponents', [tNoCaptionRadioBox]);
end;