Multimidia - desenhando texto em canvas e quebrando

Top  Previous  Next

Caption do BitBtn com várias linhas

unit Unit1; 

 

interface 

 

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls, Buttons; 

 

type

TForm1 = class(TForm)

BitBtn1: TBitBtn;

procedure FormCreate(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end

 

var

Form1: TForm1; 

 

implementation 

 

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject); 

 

var

R : TRect;

N : Integer;

Buff : array[0..255of Char;

begin

with BitBtn1 do

begin

Caption := 'Várias linhas no caption de um botão';

Glyph.Canvas.Font := Self.Font;

Glyph.Width := Width - 6;

Glyph.Height := Height - 6;

R := Bounds(00, Glyph.Width, 0);

StrPCopy(Buff, Caption);

Caption := '';

DrawText(Glyph.Canvas.Handle, Buff,StrLen(Buff),R,

DT_CENTER or DT_WORDBREAK or DT_CALCRECT);

OffsetRect(R,(Glyph.Width - R.Right) div 2,

(Glyph.Height - R.Bottom) div 2);

DrawText(Glyph.Canvas.Handle, Buff, StrLen(Buff), R,

DT_CENTER or DT_WORDBREAK);

end;

end

 

end