首页  编辑  

多行Caption的按钮、CheckBox等

Tags: /超级猛料/VCL/ToolBar和按钮、标签/   Date Created:

如何设置一个按钮用有多行Caption?

procedure TForm1 . Button1Click ( Sender : TObject );

var

 i : Integer ;

begin

 i := GetWindowLong ( Button1 . Handle , GWL_STYLE );

 SetWindowLong ( Button1 . Handle , GWL_STYLE , i or BS_MULTILINE );

 Button1 . Caption := 'Line1' + #13#10 + 'Line2' ;

end ;

改成CheckBox等一样可以。

---------------------------------------

免代码的设置:

Title: Word wrapped TButton

Author: Tomas Rutkauskas

Product: Delphi 2.x (or higher)

Post Date: 08/24/2002

Problem/Question/Abstract:

Word wrapped TButton

Answer:

If you want to have your TButton objects displayed with wrapped caption, you will notice that this is not possible - not possible without a little trick.

Of course, you could search the web for some third-party component, but there's an easier way to accomplish this. Just follow these steps:

  1. Put a TButton with empty caption on your form;
  2. Create a TLabel with your desired caption and place it anywhere on the form;
  3. Display the form as text (Alt+F12) and it will look as on the left side in the table;
  4. Move the TLabel declaration into the TButton and change the coordinates since it is now relative to the button;

(idea from Richard B. Winston:) Select the button and then "Component|Create Component Template". After you choose a name and palette page for the template, you will be able to select the button with embedded label from the component palette and use it just like any other component.

//(before step 4)

object Button1: TButton  Left = 176  Top = 184  Width = 75  Height = 25  Caption = ''  TabOrder = 2endobject Label1: TLabel  Left = 200  Top = 168  Width = 32  Height = 13  Caption = 'My long caption'  WordWrap = Trueend

// (after step 4)

object Button1: TButton  Left = 176  Top = 184  Width = 75  Height = 25  Caption = ''  TabOrder = 2  object Label1: TLabel    Left = 2    Top = 2    Width = 32    Height = 13    Caption = 'My long caption'    WordWrap = True  endend

img_25570.bmp (24.5KB)