Marco Cantù 1998, Mastering Delphi 4

Project: REALTBAR.DPR


Project Structure


REALTBAR.DPR

program RealTBar;

uses
  Forms,
  TBarForm in 'TBarForm.pas' {RealBarForm};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TRealBarForm, RealBarForm);
  Application.Run;
end.

TBARFORM.PAS

unit TBarForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ToolWin, Menus, StdCtrls, ExtCtrls, ImgList;

type
  TRealBarForm = class(TForm)
    ToolBar1: TToolBar;
    ImageList1: TImageList;
    TbNote: TToolButton;
    TbSeparator1: TToolButton;
    TbLeft: TToolButton;
    TbCenter: TToolButton;
    TbRight: TToolButton;
    TbSeparator2: TToolButton;
    TbBold: TToolButton;
    TbItalic: TToolButton;
    TbUnderlined: TToolButton;
    TbSize: TToolButton;
    TbSeparator3: TToolButton;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    exit1: TMenuItem;
    Toolbar2: TMenuItem;
    Captions1: TMenuItem;
    Label1: TLabel;
    CaptionBelow1: TMenuItem;
    Flat1: TMenuItem;
    Help1: TMenuItem;
    About1: TMenuItem;
    PopupSize: TPopupMenu;
    N101: TMenuItem;
    N141: TMenuItem;
    N181: TMenuItem;
    N142: TMenuItem;
    N361: TMenuItem;
    N721: TMenuItem;
    procedure TbNoteClick(Sender: TObject);
    procedure TbLeftClick(Sender: TObject);
    procedure TbCenterClick(Sender: TObject);
    procedure TbRightClick(Sender: TObject);
    procedure TbBoldClick(Sender: TObject);
    procedure TbItalicClick(Sender: TObject);
    procedure TbUnderlinedClick(Sender: TObject);
    procedure Captions1Click(Sender: TObject);
    procedure CaptionBelow1Click(Sender: TObject);
    procedure Flat1Click(Sender: TObject);
    procedure exit1Click(Sender: TObject);
    procedure About1Click(Sender: TObject);
    procedure OnSizeClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  RealBarForm: TRealBarForm;

implementation

{$R *.DFM}


procedure TRealBarForm.TbNoteClick(Sender: TObject);
begin
  Beep;
end;


procedure TRealBarForm.TbLeftClick(Sender: TObject);
begin
  Label1.Alignment := taLeftJustify;
end;

procedure TRealBarForm.TbCenterClick(Sender: TObject);
begin
  Label1.Alignment := taCenter;
end;

procedure TRealBarForm.TbRightClick(Sender: TObject);
begin
  Label1.Alignment := taRightJustify;
end;

procedure TRealBarForm.TbBoldClick(Sender: TObject);
begin
  Label1.Font.Style := [fsBold];
end;

procedure TRealBarForm.TbItalicClick(Sender: TObject);
begin
  Label1.Font.Style := [fsItalic];
end;

procedure TRealBarForm.TbUnderlinedClick(Sender: TObject);
begin
  Label1.Font.Style := [fsUnderline];
end;

procedure TRealBarForm.Captions1Click(Sender: TObject);
begin
  Toolbar1.ShowCaptions := not Toolbar1.ShowCaptions;
  Captions1.Checked := Toolbar1.ShowCaptions;
  CaptionBelow1.Enabled := Toolbar1.ShowCaptions;
  if Toolbar1.ShowCaptions then
  begin
    Toolbar1.ButtonWidth := 72;
    Toolbar1.ButtonHeight := 36;
  end
  else
  begin
    Toolbar1.ButtonWidth := 24;
    Toolbar1.ButtonHeight := 24;
  end;
end;

procedure TRealBarForm.CaptionBelow1Click(Sender: TObject);
begin
  CaptionBelow1.Checked := not CaptionBelow1.Checked;
  Toolbar1.List := not CaptionBelow1.Checked;
end;

procedure TRealBarForm.Flat1Click(Sender: TObject);
begin
  Toolbar1.Flat := not Toolbar1.Flat;
  Flat1.Checked := Toolbar1.Flat;
end;

procedure TRealBarForm.exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TRealBarForm.About1Click(Sender: TObject);
begin
  MessageDlg ('A real toolbar from Mastering Delphi', mtINformation,
    [mbOK], 0);
end;

procedure TRealBarForm.OnSizeClick(Sender: TObject);
begin
  Label1.Font.Size :=
    StrToInt ((Sender as TMenuItem).Caption);
  (Sender as TMenuItem).Checked := True;
end;

end.

TBARFORM.DFM

object RealBarForm: TRealBarForm
  Left = 198
  Top = 240
  Width = 650
  Height = 314
  Caption = 'Real Toolbar'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 0
    Top = 46
    Width = 642
    Height = 222
    Align = alClient
    Caption =
       'A caption with some sample text to show the effect of the speed ' +
      'buttons of the toolbar. You can replace it with something more u' +
      'seful.'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -19
    Font.Name = 'Arial'
    Font.Style = []
    ParentFont = False
    WordWrap = True
  end
  object ToolBar1: TToolBar
    Left = 0
    Top = 0
    Width = 642
    Height = 46
    AutoSize = True
    BorderWidth = 2
    ButtonHeight = 36
    ButtonWidth = 72
    Color = clBtnFace
    Flat = True
    Images = ImageList1
    Indent = 10
    ParentColor = False
    ParentShowHint = False
    ShowCaptions = True
    ShowHint = True
    TabOrder = 0
    object TbNote: TToolButton
      Left = 10
      Top = 0
      Hint = 'Play Note'
      Caption = 'Note'
      ImageIndex = 0
      OnClick = TbNoteClick
    end
    object TbSeparator1: TToolButton
      Left = 82
      Top = 0
      Width = 8
      Caption = 'TbSeparator1'
      ImageIndex = 1
      Style = tbsSeparator
    end
    object TbLeft: TToolButton
      Left = 90
      Top = 0
      Hint = 'Align Left'
      Caption = 'Left'
      Down = True
      Grouped = True
      ImageIndex = 1
      Style = tbsCheck
      OnClick = TbLeftClick
    end
    object TbCenter: TToolButton
      Left = 162
      Top = 0
      Hint = 'Center Text'
      Caption = 'Center'
      Grouped = True
      ImageIndex = 2
      Style = tbsCheck
      OnClick = TbCenterClick
    end
    object TbRight: TToolButton
      Left = 234
      Top = 0
      Hint = 'Align Right'
      Caption = 'Right'
      Grouped = True
      ImageIndex = 3
      Style = tbsCheck
      OnClick = TbRightClick
    end
    object TbSeparator2: TToolButton
      Left = 306
      Top = 0
      Width = 8
      Caption = 'TbSeparator2'
      ImageIndex = 4
      Style = tbsSeparator
    end
    object TbBold: TToolButton
      Left = 314
      Top = 0
      Hint = 'Bold Style'
      Caption = 'Bold'
      Grouped = True
      ImageIndex = 4
      Style = tbsCheck
      OnClick = TbBoldClick
    end
    object TbItalic: TToolButton
      Left = 386
      Top = 0
      Hint = 'Italic Style'
      Caption = 'Italic'
      Grouped = True
      ImageIndex = 5
      Style = tbsCheck
      OnClick = TbItalicClick
    end
    object TbUnderlined: TToolButton
      Left = 458
      Top = 0
      Hint = 'Underlined Style'
      Caption = 'Underlined'
      Grouped = True
      ImageIndex = 6
      Style = tbsCheck
      OnClick = TbUnderlinedClick
    end
    object TbSeparator3: TToolButton
      Left = 530
      Top = 0
      Width = 8
      Caption = 'TbSeparator3'
      ImageIndex = 7
      Style = tbsSeparator
    end
    object TbSize: TToolButton
      Left = 538
      Top = 0
      Hint = 'Resize Text'
      Caption = 'Size'
      DropdownMenu = PopupSize
      ImageIndex = 7
      Style = tbsDropDown
    end
  end
  object ImageList1: TImageList
    Left = 32
    Top = 120
    Bitmap = {
      360C000008000000424D360C0000000000003604000028000000400000002000
      0000010008000000000000080000000000000000000000010000000000000000
      0000000080000080000000808000800000008000800080800000C0C0C000C0DC
      C000F0CAA6000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      00000000000000000000000000000000000000000000F0FBFF00A4A0A0008080
      80000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      0000000000000000000000000000000000000000000000000000000000000000
      000000000000000000000000000000000000000000000000000000000000424D
      3E010000000000003E0000002800000040000000200000000100010000000000
      000100000000000000000000020000000000000000000000FFFFFF00FFFFFFFF
      FFFFFFFFFFFFFFFFFFFFC1FFE01FF03FF00FDFFFE00FFCFFF00FDFFFF3CFFCFF
      FFFFDFFFF3CFFCFFFC4FC3FFF38FFE7FF80FDFFFF01FFE7FF91FDF7FF00FFE7F
      F99FC1BFF3CFFF3FF99FFFDDF3CFFF3FF99FFFEDE00FFC0FF11FFFF5E01FFFFF
      FFFFFFF9FFFFFFFFFFFFFFC1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFCFFF8001
      80018001873FBFFDBFFDBFFD821FA03DB81DBC05C20FBFFDBFFDBFFDFB0FA3FD
      BC3DBFC5FBEFBFFDBFFDBFFDFBEFA0FDB81DBF05FBEFBFFDBFFDBFFDFBEFA3FD
      BE7DBFC5FBEFBFFDBFFDBFFDF8EFA01DB00DB805FB0FBFFDBFFDBFFDF8EFA07D
      B81DBE05FF0FBFFDBFFDBFFDFFFF800180018001FFFFFFFFFFFFFFFF}
  end
  object MainMenu1: TMainMenu
    Left = 32
    Top = 64
    object File1: TMenuItem
      Caption = '&File'
      object exit1: TMenuItem
        Caption = 'E&xit'
        OnClick = exit1Click
      end
    end
    object Toolbar2: TMenuItem
      Caption = '&Toolbar'
      object Captions1: TMenuItem
        Caption = '&Captions'
        Checked = True
        OnClick = Captions1Click
      end
      object CaptionBelow1: TMenuItem
        Caption = 'Caption &Below'
        Checked = True
        OnClick = CaptionBelow1Click
      end
      object Flat1: TMenuItem
        Caption = 'Flat'
        Checked = True
        OnClick = Flat1Click
      end
    end
    object Help1: TMenuItem
      Caption = '&Help'
      object About1: TMenuItem
        Caption = '&About...'
        OnClick = About1Click
      end
    end
  end
  object PopupSize: TPopupMenu
    Left = 112
    Top = 88
    object N101: TMenuItem
      Caption = '10'
      GroupIndex = 1
      RadioItem = True
      OnClick = OnSizeClick
    end
    object N141: TMenuItem
      Caption = '14'
      Checked = True
      GroupIndex = 1
      RadioItem = True
      OnClick = OnSizeClick
    end
    object N181: TMenuItem
      Caption = '18'
      GroupIndex = 1
      RadioItem = True
      OnClick = OnSizeClick
    end
    object N142: TMenuItem
      Caption = '24'
      GroupIndex = 1
      RadioItem = True
      OnClick = OnSizeClick
    end
    object N361: TMenuItem
      Caption = '36'
      GroupIndex = 1
      RadioItem = True
      OnClick = OnSizeClick
    end
    object N721: TMenuItem
      Caption = '72'
      GroupIndex = 1
      RadioItem = True
      OnClick = OnSizeClick
    end
  end
end


Copyright Marco Cantù 1998