TsSpeedButton getting the max. available width of caption

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #51083
    Support
    Keymaster

      Hello!

      'remsi' wrote:
      I have my own function taking care of wrapping the words of the caption following some complex rules.

      Before version 8.48 it was sufficient to determine the maximum available width for the caption using MySpeedButton.Width – 8 (which is actually not a good solution).

      This solution no longer works because now the caption is automatically wordwrapped resulting in some messy layout.

      You can calculate maximal allowed width of text using this code:

      Code:
      uses ComCtrls;

      function GetMaxTextWidth(Btn: TsSpeedButton): integer;
      var
      iGlyphWidth, iMargin: integer;
      begin
      with Btn do begin
      if (Glyph <> nil) then
      iGlyphWidth := Glyph.Width div NumGlyphs
      else
      if Assigned(Images) then
      iGlyphWidth := Images.Width div NumGlyphs
      else
      iGlyphWidth := 0;

      if Margin < 0 then
      iMargin := 0
      else
      iMargin := Margin + 3;

      Result := Width – 16 * integer(ButtonStyle = tbsDropDown) – iGlyphWidth – Spacing * integer((iGlyphWidth > 0) and (Caption <> '')) – iMargin * 2;
      end;
      end;

      Same code should work for TsBitBtn too.

      Quote:
      Quick and dirty:

      Is it possible to disable the automatic wrapping? Setting MySpeedButton.WordWrap := false will also ignore the CR-LF I placed.

      CR-LF is working always, even if WordWrap property is False.

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.