Вот полный код проекта, создающего на кнопке во время выполнения две строчки текста.
Файл TWOLNBTN.DPR
program TwolnBtn;
uses Forms, TwolnBtu in 'TWOLNBTU.PAS' {Form1}; {$R *.RES} begin Application.CreateForm(TForm1, Form1); Application.Run; end. |
Файл TWOLNBTU.TXT => TWOLNBTU.DFM
object Form1: TForm1 Left = 202 Top = 98 Width = 320 Height = 176 Caption = 'Form1' Font.Color = clRed Font.Height = -12 Font.Name = 'Arial' Font.Style = [fsBold] PixelsPerInch = 96 OnActivate = ChgSpeedButton OnCreate = ChgBitBtn TextHeight = 15 object SpeedButton1: TSpeedButton Left = 144 Top = 24 Width = 65 Height = 45 Caption = 'Это двустрочный заголовок' OnClick = ChgSpeedButton end object BitBtn1: TBitBtn Left = 32 Top = 24 Width = 69 Height = 37 Caption = 'Прерывание работы программы' TabOrder = 0 OnClick = BitBtn1Click end end |
Файл TWOLNBTU.PAS
unit Twolnbtu;
interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; type TForm1 = class(TForm) BitBtn1: TBitBtn; SpeedButton1: TSpeedButton; procedure ChgBitBtn(Sender: TObject); procedure ChgSpeedButton(Sender: TObject); procedure BitBtn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.ChgBitBtn(Sender: TObject); VAR R : TRect; N : Integer; Buff : ARRAY[0..255] OF Char; BEGIN WITH BitBtn1 DO BEGIN Glyph.Canvas.Font := Self.Font; Glyph.Width := Width-6; Glyph.Height := Height-6; R := Bounds(0,0,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; procedure TForm1.ChgSpeedButton(Sender: TObject); VAR R : TRect; N : Integer; Buff : ARRAY[0..255] OF Char; BEGIN WITH SpeedButton1 DO BEGIN Glyph.Canvas.Font := Self.Font; Glyph.Width := Width-6; Glyph.Height := Height-6; R := Bounds(0,0,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; procedure TForm1.BitBtn1Click(Sender: TObject); begin Close; end; end. |
-Dennis Passmore [001062]