加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 在Delphi表单上递归更新字体

发布时间:2020-12-14 02:08:26 所属栏目:Windows 来源:网络整理
导读:我正在尝试迭代窗体上的所有控件并启用ClearType字体平滑.像这样的东西: procedure TForm4.UpdateControls(AParent: TWinControl);var I: Integer; ACtrl: TControl; tagLOGFONT: TLogFont;begin for I := 0 to AParent.ControlCount-1 do begin ACtrl:= AP
我正在尝试迭代窗体上的所有控件并启用ClearType字体平滑.像这样的东西:

procedure TForm4.UpdateControls(AParent: TWinControl);
var
  I: Integer;
  ACtrl: TControl;
  tagLOGFONT: TLogFont;
begin
  for I := 0 to AParent.ControlCount-1 do
  begin
    ACtrl:= AParent.Controls[I];

    // if ParentFont=False,update the font here...

    if ACtrl is TWinControl then
      UpdateControls(Ctrl as TWinControl);
  end;
end;

现在,是否有一种简单的方法可以检查ACtrl是否具有Font属性,因此我可以将Font.Handle传递给somethink,如:

GetObject(ACtrl.Font.Handle,SizeOf(TLogFont),@tagLOGFONT);
tagLOGFONT.lfQuality := 5;
ACtrl.Font.Handle := CreateFontIndirect(tagLOGFONT);

先感谢您.

解决方法

您使用TypInfo单元,更具体地说是方法IsPublishedProp和GetOrdProp.

在你的情况下,它将是这样的:

if IsPublishedProp(ACtrl,'Font') then
  ModifyFont(TFont(GetOrdProp(ACtrl,'Font')))

来自我的一个库的片段应该让您走上正确的道路:

function ContainsNonemptyControl(controlParent: TWinControl;
  const requiredControlNamePrefix: string;
  const ignoreControls: string = ''): boolean;
var
  child   : TControl;
  iControl: integer;
  ignored : TStringList;
  obj     : TObject;
begin
  Result := true;
  if ignoreControls = '' then
    ignored := nil
  else begin
    ignored := TStringList.Create;
    ignored.Text := ignoreControls;
  end;
  try
    for iControl := 0 to controlParent.ControlCount-1 do begin
      child := controlParent.Controls[iControl];
      if (requiredControlNamePrefix = '') or
         SameText(requiredControlNamePrefix,Copy(child.Name,1,Length(requiredControlNamePrefix))) then
      if (not assigned(ignored)) or (ignored.IndexOf(child.Name) < 0) then
      if IsPublishedProp(child,'Text') and (GetStrProp(child,'Text') <> '') then
        Exit
      else if IsPublishedProp(child,'Lines') then begin
        obj := TObject(cardinal(GetOrdProp(child,'Lines')));
        if (obj is TStrings) and (Unwrap(TStrings(obj).Text,child) <> '') then
          Exit;
      end;
    end; //for iControl
  finally FreeAndNil(ignored); end;
  Result := false;
end; { ContainsNonemptyControl }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读