Delphi TToolButton 文本左对齐?

问题描述 投票:0回答:0

使用德尔福 11.3。 我有一个带有 vertical TToolButtons 列表的 TToolbar,在文本模式下。 在设计时,按钮中的文本是左对齐的。 在运行时,他在按钮中的文本居中。

有什么办法可以强制将文本直接放在图标旁边?

我在 Vcl.ComCtrls 中找到了绘图代码,在程序 TToolBarStyleHook.Paint(Canvas: TCanvas);

 if (WStyle and TBSTYLE_LIST = TBSTYLE_LIST) then
      begin
        sRect := R;
        Canvas.Font := TControlClass(Control).Font;
        DrawText(Canvas.Handle, PChar(Info.pszText),
          Length(Info.pszText), sRect, DT_CENTER or DT_WORDBREAK or DT_CALCRECT);
        RectCenter(sRect, R);
        if ImageDrawed and (Info.iImage >= 0) and (FImages <> nil) then
        begin
          iRect := Rect(5, iRect.Top, FImages.Width + 5, iRect.Bottom);
          OffsetRect(iRect, R.Left, 0);
          sRect := Rect(iRect.Right + 3, sRect.Top, R.Right, sRect.Bottom);
        end;
        if DrawButtonFace then
          DrawControlText(Canvas, Details, Info.pszText, sRect, DT_LEFT or DT_WORDBREAK)
        else
        begin
          if ButtonState <> ttbButtonDisabled then
            Canvas.Font.Color := LStyle.GetSystemColor(clBtnText)
          else
            Canvas.Font.Color := LStyle.GetSystemColor(clGrayText);
          SetBkMode(Canvas.Handle, Transparent);
          DrawText(Canvas.Handle, Info.pszText, Length(Info.pszText), sRect,
            DT_LEFT or DT_WORDBREAK);
        end;
      end

现在,如果 DT_CENTER 改为 DT_LEFT,我的问题可能会得到解决...... 有什么办法可以覆盖这个吗?

windows delphi button
© www.soinside.com 2019 - 2024. All rights reserved.