Marco Cantù 1998, Mastering Delphi 4

Project: PANELBAR.DPR


Project Structure


PANELBAR.DPR

program PanelBar;

uses
  Forms,
  PanelBF in 'PanelBF.pas' {ToolbarForm};

{$R *.RES}

begin
  Application.CreateForm(TToolbarForm, ToolbarForm);
  Application.Run;
end.

PANELBF.PAS

unit PanelBF;

interface

uses
  Windows, SysUtils, Classes, Graphics, Forms, Controls,
  Menus, Buttons, StdCtrls, Dialogs, ExtCtrls;

type
  TToolbarForm = class(TForm)
    Panel1: TPanel;
    SpeedButtonNote: TSpeedButton;
    SpeedButtonBig: TSpeedButton;
    SpeedButtonBold: TSpeedButton;
    SpeedButtonItalic: TSpeedButton;
    SpeedButtonUnderline: TSpeedButton;
    SpeedButtonLeft: TSpeedButton;
    SpeedButtonCenter: TSpeedButton;
    SpeedButtonRight: TSpeedButton;
    Label1: TLabel;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    Toolbar1: TMenuItem;
    Visible1: TMenuItem;
    DisableSound1: TMenuItem;
    DisableStyles1: TMenuItem;
    Help1: TMenuItem;
    AboutToolbar1: TMenuItem;
    DisableSize1: TMenuItem;
    N1: TMenuItem;
    HintColor1: TMenuItem;
    ColorDialog1: TColorDialog;
    FlatStyle1: TMenuItem;
    procedure SpeedButtonNoteClick(Sender: TObject);
    procedure SpeedButtonLeftClick(Sender: TObject);
    procedure SpeedButtonCenterClick(Sender: TObject);
    procedure SpeedButtonRightClick(Sender: TObject);
    procedure SpeedButtonBoldClick(Sender: TObject);
    procedure SpeedButtonItalicClick(Sender: TObject);
    procedure SpeedButtonUnderlineClick(Sender: TObject);
    procedure SpeedButtonBigClick(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure Visible1Click(Sender: TObject);
    procedure DisableSound1Click(Sender: TObject);
    procedure DisableStyles1Click(Sender: TObject);
    procedure AboutToolbar1Click(Sender: TObject);
    procedure DisableSize1Click(Sender: TObject);
    procedure HintColor1Click(Sender: TObject);
    procedure FlatStyle1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ToolbarForm: TToolbarForm;

implementation

{$R *.DFM}

procedure TToolbarForm.SpeedButtonNoteClick(Sender: TObject);
begin
  Beep;
end;

procedure TToolbarForm.SpeedButtonLeftClick(Sender: TObject);
begin
  Label1.Alignment := taLeftJustify;
end;

procedure TToolbarForm.SpeedButtonCenterClick(Sender: TObject);
begin
  Label1.Alignment := taCenter;
end;

procedure TToolbarForm.SpeedButtonRightClick(Sender: TObject);
begin
  Label1.Alignment := taRightJustify;
end;

procedure TToolbarForm.SpeedButtonBoldClick(Sender: TObject);
begin
  if SpeedButtonBold.Down then
    Label1.Font.Style := [fsBold]
  else
    Label1.Font.Style := [];
end;

procedure TToolbarForm.SpeedButtonItalicClick(Sender: TObject);
begin
  if SpeedButtonItalic.Down then
    Label1.Font.Style := [fsItalic]
  else
    Label1.Font.Style := [];
end;

procedure TToolbarForm.SpeedButtonUnderlineClick(Sender: TObject);
begin
  if SpeedButtonUnderline.Down then
    Label1.Font.Style := [fsUnderline]
  else
    Label1.Font.Style := [];
end;

procedure TToolbarForm.SpeedButtonBigClick(Sender: TObject);
begin
  if SpeedButtonBig.Down then
  begin
    Label1.Font.Size := 24;
    SpeedButtonBig.Hint := 'Shrink';
  end
  else
  begin
    Label1.Font.Size := 12;
    SpeedButtonBig.Hint := 'Expand';
  end;
end;

procedure TToolbarForm.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TToolbarForm.Visible1Click(Sender: TObject);
begin
  {hide or display the toolbar, setting the maneitem checkmark}
  Panel1.Visible := not Panel1.Visible;
  Visible1.Checked := not Visible1.Checked;
end;

procedure TToolbarForm.DisableSound1Click(Sender: TObject);
begin
  {disable or enable button and set menu check mark}
  SpeedButtonNote.Enabled := not SpeedButtonNote.Enabled;
  DisableSound1.Checked := not DisableSound1.Checked;
end;

procedure TToolbarForm.DisableStyles1Click(Sender: TObject);
begin
  {disable or enable buttons and set menu text properly}
  if SpeedButtonBold.Enabled then
  begin
    SpeedButtonBold.Enabled := False;
    SpeedButtonItalic.Enabled := False;
    SpeedButtonUnderline.Enabled := False;
    DisableStyles1.Checked := True;
  end
  else
  begin
    SpeedButtonBold.Enabled := True;
    SpeedButtonItalic.Enabled := True;
    SpeedButtonUnderline.Enabled := True;
    DisableStyles1.Checked := False;
  end;
end;

procedure TToolbarForm.AboutToolbar1Click(Sender: TObject);
begin
  MessageDlg ('Toolbar example for "Mastering Delphi"' +
    Chr (13) +  'Written by Marco Cantù',
    mtInformation, [mbOk], 0);
end;

procedure TToolbarForm.DisableSize1Click(Sender: TObject);
begin
  SpeedButtonBig.Enabled := not SpeedButtonBig.Enabled;
  DisableSize1.Checked := not DisableSize1.Checked;
end;

procedure TToolbarForm.HintColor1Click(Sender: TObject);
begin
  ColorDialog1.Color := Application.HintColor;
  if ColorDialog1.Execute then
    Application.HintColor := ColorDialog1.Color;
end;

procedure TToolbarForm.FlatStyle1Click(Sender: TObject);
var
  I: Integer;
begin
  FlatStyle1.Checked := not FlatStyle1.Checked;
  for I := 0 to Panel1.ControlCount - 1 do
    (Panel1.Controls [I] as TSpeedButton).Flat :=
       FlatStyle1.Checked;
end;

end.

PANELBF.DFM

object ToolbarForm: TToolbarForm
  Left = 305
  Top = 225
  Width = 366
  Height = 326
  ActiveControl = Panel1
  Caption = 'Toolbar'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'System'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = True
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 0
    Top = 33
    Width = 358
    Height = 247
    Align = alClient
    AutoSize = False
    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 = -16
    Font.Name = 'Arial'
    Font.Style = []
    ParentFont = False
    WordWrap = True
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 358
    Height = 33
    Align = alTop
    BevelWidth = 2
    ParentShowHint = False
    ShowHint = True
    TabOrder = 0
    object SpeedButtonNote: TSpeedButton
      Left = 8
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Play Note'
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003330033333333333330000003300003330033333330000003300
        0003000033333300000033300003000003333300000033333303300003333300
        0000333333033333033333000000333333033333033333000000333333033333
        0333330000003333330333330333330000003333330333330333330000003333
        3300033303333300000033333303300003333300000033333300033303333300
        0000333333333000033333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonNoteClick
    end
    object SpeedButtonBig: TSpeedButton
      Left = 213
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Expand'
      AllowAllUp = True
      GroupIndex = 3
      Flat = True
      Glyph.Data = {
        DA020000424DDA02000000000000760000002800000048000000110000000100
        0400000000006402000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333333333333333333333333333333333333333333333333333333333333333
        333333333333333333FFFFF33333333333333333333333333333333333333333
        3333333000003333333333333888883333333333333000000333333333333000
        0003333333333330333333333333333338F33333333333333330333333333333
        333330333333333333333330333333333333333338F333333333333333303333
        33333333333330333333333333333330333333333333333338FFFF3333333333
        3330333333333333333330333333333333333330000333333333333338888333
        3333333333303333333333333333303333333333333333303333333333333333
        38F3333333333333333000003333333333333000003333333333333033333033
        3333333338FFFFF8F33333333330333333333333333330333333333333333330
        0000330333333333388888338F3333F333303333333333333333303333333333
        3333333333333330333033333333333338F338F3333033333330333033333033
        3333300000333333333333330330333333333333338F38F33330333333330330
        3333303333333003333333333333333330303333333333333338F8F333300000
        0333303033333000000330303333333333333333330033333333333333FF88F3
        3333333333333300333333333333303303333333333333300000333333333333
        3888883333333333333000003333333333333033303333333333333333333333
        3333333333333333333333333333333333333333333333333303333333333333
        333333333333333333333333333333333333333333333333333333333333}
      NumGlyphs = 4
      OnClick = SpeedButtonBigClick
    end
    object SpeedButtonBold: TSpeedButton
      Left = 128
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Bold'
      AllowAllUp = True
      GroupIndex = 2
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003333333333333333330000003333333333333333330000003333
        0000000033333300000033330000000003333300000033333003333003333300
        0000333330033330033333000000333330033300033333000000333330000000
        3333330000003333300000000333330000003333300333300333330000003333
        3003333003333300000033330000000003333300000033330000000033333300
        0000333333333333333333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonBoldClick
    end
    object SpeedButtonItalic: TSpeedButton
      Left = 153
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Italic'
      AllowAllUp = True
      GroupIndex = 2
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003333333333333333330000003333333333333333330000003333
        3000000333333300000033333330033333333300000033333330033333333300
        0000333333300333333333000000333333330033333333000000333333330033
        3333330000003333333300333333330000003333333330033333330000003333
        3333300333333300000033333330000003333300000033333333333333333300
        0000333333333333333333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonItalicClick
    end
    object SpeedButtonUnderline: TSpeedButton
      Left = 178
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Underlined'
      AllowAllUp = True
      GroupIndex = 2
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        3333330000003333333333333333330000003333333333333333330000003333
        3000000003333300000033333000000003333300000033333333333333333300
        0000333333300030033333000000333333000000033333000000333333003000
        3333330000003333330033003333330000003333330033003333330000003333
        3300330033333300000033333000300033333300000033333333333333333300
        0000333333333333333333000000333333333333333333000000333333333333
        333333000000}
      OnClick = SpeedButtonUnderlineClick
    end
    object SpeedButtonLeft: TSpeedButton
      Left = 43
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Left Align'
      GroupIndex = 1
      Down = True
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        333333000000330000000000000033000000330FFFFFFFFFFFF033000000330F
        0000000FFFF033000000330FFFFFFFFFFFF033000000330F000FFFFFFFF03300
        0000330FFFFFFFFFFFF033000000330F00000FFFFFF033000000330FFFFFFFFF
        FFF033000000330F000FFFFFFFF033000000330FFFFFFFFFFFF033000000330F
        00000000FFF033000000330FFFFFFFFFFFF033000000330F000000FFFFF03300
        0000330FFFFFFFFFFFF033000000330000000000000033000000333333333333
        333333000000}
      OnClick = SpeedButtonLeftClick
    end
    object SpeedButtonCenter: TSpeedButton
      Left = 68
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Center'
      GroupIndex = 1
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        333333000000330000000000000033000000330FFFFFFFFFFFF033000000330F
        FF000000FFF033000000330FFFFFFFFFFFF033000000330FFFF0000FFFF03300
        0000330FFFFFFFFFFFF033000000330FFF000000FFF033000000330FFFFFFFFF
        FFF033000000330FFFFF00FFFFF033000000330FFFFFFFFFFFF033000000330F
        F00000000FF033000000330FFFFFFFFFFFF033000000330FFF000000FFF03300
        0000330FFFFFFFFFFFF033000000330000000000000033000000333333333333
        333333000000}
      OnClick = SpeedButtonCenterClick
    end
    object SpeedButtonRight: TSpeedButton
      Left = 93
      Top = 4
      Width = 25
      Height = 25
      Hint = 'Right Align'
      GroupIndex = 1
      Flat = True
      Glyph.Data = {
        42010000424D4201000000000000760000002800000012000000110000000100
        040000000000CC00000000000000000000001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00333333333333
        333333000000330000000000000033000000330FFFFFFFFFFFF033000000330F
        FFF0000000F033000000330FFFFFFFFFFFF033000000330FFFFFFFF000F03300
        0000330FFFFFFFFFFFF033000000330FFFFFF00000F033000000330FFFFFFFFF
        FFF033000000330FFFFFFFF000F033000000330FFFFFFFFFFFF033000000330F
        FF00000000F033000000330FFFFFFFFFFFF033000000330FFFFF000000F03300
        0000330FFFFFFFFFFFF033000000330000000000000033000000333333333333
        333333000000}
      OnClick = SpeedButtonRightClick
    end
  end
  object MainMenu1: TMainMenu
    Left = 32
    Top = 56
    object File1: TMenuItem
      Caption = '&File'
      object Exit1: TMenuItem
        Caption = 'E&xit'
        OnClick = Exit1Click
      end
    end
    object Toolbar1: TMenuItem
      Caption = '&Toolbar'
      object Visible1: TMenuItem
        Caption = '&Visible'
        Checked = True
        OnClick = Visible1Click
      end
      object DisableSound1: TMenuItem
        Caption = 'Disable &Sound'
        OnClick = DisableSound1Click
      end
      object DisableStyles1: TMenuItem
        Caption = 'Disable S&tyles'
        OnClick = DisableStyles1Click
      end
      object DisableSize1: TMenuItem
        Caption = 'Disable Si&ze'
        OnClick = DisableSize1Click
      end
      object N1: TMenuItem
        Caption = '-'
      end
      object HintColor1: TMenuItem
        Caption = '&Hint Color...'
        OnClick = HintColor1Click
      end
      object FlatStyle1: TMenuItem
        Caption = '&Flat Style'
        Checked = True
        OnClick = FlatStyle1Click
      end
    end
    object Help1: TMenuItem
      Caption = '&Help'
      object AboutToolbar1: TMenuItem
        Caption = '&About Toolbar...'
        OnClick = AboutToolbar1Click
      end
    end
  end
  object ColorDialog1: TColorDialog
    Ctl3D = True
    Left = 32
    Top = 104
  end
end


Copyright Marco Cantù 1998