We help IT Professionals succeed at work.

Multiline TCheckBox

albireo77
albireo77 asked
on
Medium Priority
1,029 Views
Last Modified: 2010-04-05
Hi there,

Is there a possibility to create TCheckBox with multiline caption? I have additional TLabel acting as a second line. It's better than nothing but really sucks. I have tried something like Caption := 'Line1'#13#10'Line2';  but didn't work.

Regards,
albi
Comment
Watch Question

Maybe you will found here what your are looking for :
http://www.sparksoftcomponents.com/
Also, if yo ua re using delphi5, a extra cd is shipped with LMD-Tools component-package on it.
If you install these components, then you have a multiline Checkbox also (tab LMD Std)
Engineer
Commented:
If you want to have a little fun and do this yourself without a third party component, try this little sneaky method.

http://delphi.about.com/c/ht/00/07/How_Create_Word_Wrapped0962933210.htm

Works for buttons, but Im assuming it should work for a TCheckbox too  

:o)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Indeed, this is xorking too.
Delphi is such a great tool. Really Object Oriented.

Only disadvantage is that you still have 2 Components on your form (a TCheckBox and a TLabel in it).

I guess this is what albireo77 was trying to avoid.

But it can be a workaround if you don't want to make use of 3rd party components.
Mike LittlewoodEngineer

Commented:
btw, I presume you are not using Delphi 7 then as wordwrapping comes as standard for TCheckbox, TButton etc
Eddie ShipmanAll-around developer
CERTIFIED EXPERT

Commented:
This makes all the checkboxes you drop on a form have a Wordwrap property, hence, multi-line:
{Note, the property won't show in the Object Inspector but it will be avail}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TCheckBox = class(StdCtrls.TCheckBox)
  private
    FWordWrap: Boolean;
    procedure SetWordWrap(const Value: Boolean);
  protected
    procedure CreateParams(var Params: TCreateParams); override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property WordWrap: Boolean read FWordWrap write SetWordWrap default False;
  end;

  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TCheckBox }

constructor TCheckBox.Create(AOwner: TComponent);
begin
  inherited;
  FWordWrap := True;
end;

procedure TCheckBox.CreateParams(var Params: TCreateParams);
begin
  inherited;
  if FWordWrap then
    Params.Style := Params.Style or BS_MULTILINE;
end;

procedure TCheckBox.SetWordWrap(const Value: Boolean);
begin
  if FWordWrap <> Value then
  begin
    FWordWrap := Value;
    RecreateWnd;
  end;
end;

end.


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.