TBitBtnLayout (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example uses a bitmap button on a form that has a bitmap specified as the value of its Glyph property. When the user clicks the bitmap button, the bitmap randomly changes its position on the button:

Code

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

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  bmap: TBitmap;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  RNum: Integer;
begin
  RNum := Random(4);
  case RNum of
    0: BitBtn1.Layout := blGlyphLeft;
    1: BitBtn1.Layout := blGlyphRight;
    2: BitBtn1.Layout := blGlyphTop;
    3: BitBtn1.Layout := blGlyphBottom;
    else
      ShowMessage('Unhandled case');
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  bmap: TBitmap;
begin
  bmap := TBitmap.Create();
  bmap.LoadFromFile('littleB_16.bmp');
  BitBtn1.Glyph:= bmap;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bmap.Free;
end;

Uses