Jump to content
PeterPanettone

Bug in TButton with Multi-Line Caption?

Recommended Posts

Posted (edited)

At design-time:

 

image.png.43d76e1b6bc51d8d29e644b2fd591016.png

 

image.png.3f04e29c1d09fc6d0cc983782577a2d8.png

 

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Caption := 'Back' + #13#10 + 'to Editor';
end;

 

At run-time:

 

image.thumb.png.630250644c4ccc699d5461206f62ebf8.png

 

TButtonMultiLineCaptionTest.zip

 

Can anyone confirm this?

 

Is there a working "Quality Portal" where this can be reported?

Edited by PeterPanettone

Share this post


Link to post

Is this with Delphi 12 - Athens?  Could it be related to this issue mentioned on Stack Overflow?  To test if that's the issue just try changing #13#10 to + #13 + #10 to see if it makes a difference.

 

Stack Overflow: Issue related to character literals:

 

https://stackoverflow.com/a/78186835/113128

Share this post


Link to post
Posted (edited)

You can solve this problem, set Wordwrap to true.

 

It is event documented:

 

Vcl.StdCtrls.TButton.WordWrap inherits from Vcl.StdCtrls.TButtonControl.WordWrap. All content below this line refers to Vcl.StdCtrls.TButtonControl.WordWrap. 

 

Specifies whether the button text wraps to fit the width of the control. 

Set WordWrap to true to allow the display of multiple lines of text. When WordWrap is true, text that is too wide for the control wraps at the right margin. 

Set WordWrap to false to limit the text to a single line. When WordWrap is false, text that is too wide for the control appears truncated. 

Edited by Lajos Juhász
copied from help.

Share this post


Link to post

In TRzButton the Multi-Line Caption works without having to explicitly set WordWrap = True:

 

image.png.b5ac92dce1a95dec358e243d192d323d.png

Share this post


Link to post
Posted (edited)
23 hours ago, Lajos Juhász said:

When WordWrap is true, text that is too wide for the control wraps at the right margin.

This is not concisely logical, as it should word-wrap the Caption when the "text is too wide for the control" AND NOT PREVENT the word-wrap when it is already Multi-Line (if WordWrap = False).

 

And, from a purely practical point of view, what sense would it make to explicitly truncate the text if it's too large for the control? Wouldn't it rather be more practical to automatically word-wrap the Caption when the text is too large for the control?

Edited by PeterPanettone

Share this post


Link to post
2 hours ago, PeterPanettone said:

This is not concisely logical, as it should word-wrap the Caption when the "text is too wide for the control" AND NOT PREVENT the word-wrap when it is already Multi-Line (if WordWrap = False).

 

And, from a purely practical point of view, what sense would it make to explicitly truncate the text if it's too short for the control? Wouldn't it rather be more practical to automatically word-wrap the Caption when the text is too short for the control?

It may not be logical but Windows has a lot of these little inconsistencies that have accumulated over time by bolting more functionality on existing control classes. TButton is a wrapper around the Windows button control, and its behaviour is determined by the set of button control styles, in this case the BS_MULTILINE style, which the Multiline property surfaces.

Share this post


Link to post
2 minutes ago, PeterBelow said:

Windows has a lot of these little inconsistencies that have accumulated over time by bolting more functionality on existing control classes.

You are right - one should write a book about this topic.

Share this post


Link to post
6 hours ago, MarkShark said:

Is this with Delphi 12 - Athens?  Could it be related to this issue mentioned on Stack Overflow?  To test if that's the issue just try changing #13#10 to + #13 + #10 to see if it makes a difference.

 

Stack Overflow: Issue related to character literals:

 

https://stackoverflow.com/a/78186835/113128

That is a completely different issue.  I don't see how that applies here.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×