Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to implement a multi-line caption on a TButton Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
26-Aug-02
Category
VCL-General
Language
Delphi All Versions
Views
108
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas 

How do I make a button have a two line caption? I think there is a character or 
sequence there to embed a linefeed in the caption property.

Answer:

It is not as simple as adding a #13#10 sequence as a line break in the caption. You 
also need to add the BS_MULTILINE style. The following sample component will accept 
a pipe character ("|") in the caption as proxy for a linebreak. This allows you to 
specify the break in the designer, which does not accept Return as part of the 
caption string.

1   unit MLButton;
2   
3   interface
4   
5   uses
6     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
7   StdCtrls;
8   
9   type
10    TMultilineButton = class(TButton)
11    private
12      FMultiline: Boolean;
13      function GetCaption: string;
14      procedure SetCaption(const Value: string);
15      procedure SetMultiline(const Value: Boolean);
16    public
17      procedure CreateParams(var params: TCreateParams); override;
18      constructor Create(aOwner: TComponent); override;
19    published
20      property Multiline: Boolean read FMultiline write SetMultiline default True;
21      property Caption: string read GetCaption write SetCaption;
22    end;
23  
24  procedure register;
25  
26  implementation
27  
28  procedure register;
29  begin
30    RegisterComponents('PBGoodies', [TMultilineButton]);
31  end;
32  
33  constructor TMultilineButton.Create(aOwner: TComponent);
34  begin
35    inherited;
36    FMultiline := True;
37  end;
38  
39  procedure TMultilineButton.CreateParams(var params: TCreateParams);
40  begin
41    inherited;
42    if FMultiline then
43      params.Style := params.Style or BS_MULTILINE;
44  end;
45  
46  function TMultilineButton.GetCaption: string;
47  begin
48    Result := Stringreplace(inherited Caption, #13, '|', [rfReplaceAll]);
49  end;
50  
51  procedure TMultilineButton.SetCaption(const Value: string);
52  begin
53    if value <> Caption then
54    begin
55      inherited Caption := Stringreplace(value, '|', #13, [rfReplaceAll]);
56      Invalidate;
57    end;
58  end;
59  
60  procedure TMultilineButton.SetMultiline(const Value: Boolean);
61  begin
62    if FMultiline <> Value then
63    begin
64      FMultiline := Value;
65      RecreateWnd;
66    end;
67  end;
68  
69  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC