Can Delphi themed toolbars have dividers that are centred between their tool buttons?

后端 未结 3 1988
暗喜
暗喜 2020-12-11 17:27

I have noticed a rather annoying oddity with Delphi toolbars. I have a TToolbar that has logical groups of icons. To make the grouping stand out I would like to

3条回答
  •  一生所求
    2020-12-11 17:51

    The native control draws the vertical line for a separator button when the toolbar has the flat style. So if you remove the flat style, you'd be left alone with the VCL's divider line. You can safely remove the style when the application is themed, themed toolbar buttons does not regard flat style (why toolbar separators does, I have no idea). However when themes are disabled there'll again be two lines. In that case keeping separators instead of dividers seems like the better option.

    One would guess unsetting the Flat property would have any effect as the documentation states. However TToolBar.CreateParams unconditionally enables it when StyleServices is enabled. So an API call is necessary;

    procedure TForm1.FormCreate(Sender: TObject);
    var
      TbStyle: DWORD;
    begin
      if StyleServices.Enabled then begin
        TbStyle := SendMessage(ToolBar1.Handle, TB_GETSTYLE, 0, 0);
        SendMessage(Toolbar1.Handle, TB_SETSTYLE, 0, TbStyle and not TBSTYLE_FLAT);
      end;
    end;
    


    This eliminates part of the problem, the remaining part is the divider line is not exactly in the center between two buttons. VCL's problem here is, it does not want to draw the line itself. So it calls the theme api which draws the separator line to the left of the separator. To circumvent, VCL passes about the right half of the separator rectangle to the api, and the line gets about in the middle. I don't know if there's any way to tell exactly where the theme api draws it and I doubt there is.

提交回复
热议问题