Marco Cantù 1998, Mastering Delphi 4

Project: COOLBAR.DPR


Project Structure


COOLBAR.DPR

program CoolBar;

uses
  Forms,
  CoolForm in 'CoolForm.pas' {CoolbarForm};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TCoolbarForm, CoolbarForm);
  Application.Run;
end.

COOLFORM.PAS

unit CoolForm;

interface

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

type
  TCoolbarForm = class(TForm)
    CoolBar1: TCoolBar;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    ToolButton5: TToolButton;
    ColorGrid1: TColorGrid;
    Label1: TLabel;
    ImageListHighlight: TImageList;
    ImageListNormal: TImageList;
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ColorGrid1Change(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  CoolbarForm: TCoolbarForm;

implementation

{$R *.DFM}


procedure TCoolbarForm.ToolButton1Click(Sender: TObject);
begin
  Beep;
end;

procedure TCoolbarForm.ToolButton2Click(Sender: TObject);
begin
  Label1.Alignment := taLeftJustify;
end;

procedure TCoolbarForm.ToolButton3Click(Sender: TObject);
begin
  Label1.Alignment := taCenter;
end;

procedure TCoolbarForm.ToolButton4Click(Sender: TObject);
begin
  Label1.Alignment := taRightJustify;
end;

procedure TCoolbarForm.ColorGrid1Change(Sender: TObject);
begin
  Label1.Color := ColorGrid1.BackgroundColor;
  Label1.Font.Color := ColorGrid1.ForegroundColor;
end;

procedure TCoolbarForm.Edit1Change(Sender: TObject);
var
  Value: Integer;
begin
  Value := StrToIntDef (Edit1.Text, 0);
  if Value <> 0 then
    Label1.Font.Size := Value;
end;

procedure TCoolbarForm.FormCreate(Sender: TObject);
begin
  ComboBox1.Items := Screen.Fonts;
  // select the current font
  ComboBox1.ItemIndex := ComboBox1.Items.IndexOf (Font.Name);
end;

               procedure TCoolbarForm.ComboBox1Change(Sender: TObject);
begin
  Label1.Font.Name := Combobox1.Text;
end;

end.

COOLFORM.DFM

object CoolbarForm: TCoolbarForm
  Left = 196
  Top = 107
  Width = 712
  Height = 377
  Caption = 'CoolbarForm'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clBlack
  Font.Height = -13
  Font.Name = 'Arial'
  Font.Style = []
  OldCreateOrder = True
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 16
  object Label1: TLabel
    Left = 0
    Top = 69
    Width = 704
    Height = 281
    Align = alClient
    Caption =
       'This is the text of the label, very bare if you compare it with ' +
      'the really cool toolbar at the top of this form...'
    Font.Charset = ANSI_CHARSET
    Font.Color = clBlack
    Font.Height = -27
    Font.Name = 'Arial'
    Font.Style = []
    ParentFont = False
    WordWrap = True
  end
  object TLabel
    Left = 200
    Top = 224
    Width = 4
    Height = 16
  end
  object CoolBar1: TCoolBar
    Left = 0
    Top = 0
    Width = 704
    Height = 69
    AutoSize = True
    BandBorderStyle = bsNone
    Bands = <
      item
        Break = False
        Control = ToolBar1
        HorizontalOnly = True
        ImageIndex = 0
        MinHeight = 33
        Text = 'Toolbar'
        Width = 595
      end
      item
        Break = False
        Control = Edit1
        ImageIndex = 0
        Text = 'Size'
        Width = 101
      end
      item
        Control = ColorGrid1
        HorizontalOnly = True
        ImageIndex = 0
        MinHeight = 16
        Text = 'Color'
        Width = 75
      end
      item
        Break = False
        Control = ComboBox1
        ImageIndex = 0
        MinHeight = 28
        Text = 'Fonts'
        Width = 621
      end>
    BorderWidth = 1
    Font.Charset = ANSI_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    ParentShowHint = False
    Bitmap.Data = {...skipped...}
    ShowHint = True
    object ComboBox1: TComboBox
      Left = 137
      Top = 33
      Width = 555
      Height = 28
      ItemHeight = 20
      TabOrder = 0
      OnChange = ComboBox1Change
    end
    object ColorGrid1: TColorGrid
      Left = 58
      Top = 39
      Width = 0
      Height = 16
      GridOrdering = go16x1
      BackgroundIndex = 7
      TabOrder = 1
      OnChange = ColorGrid1Change
    end
    object Edit1: TEdit
      Left = 646
      Top = 4
      Width = 46
      Height = 25
      TabOrder = 2
      OnChange = Edit1Change
    end
    object ToolBar1: TToolBar
      Left = 76
      Top = 0
      Width = 515
      Height = 33
      Align = alNone
      ButtonHeight = 26
      ButtonWidth = 126
      EdgeBorders = []
      EdgeInner = esNone
      EdgeOuter = esNone
      Flat = True
      HotImages = ImageListHighlight
      Images = ImageListNormal
      Indent = 10
      List = True
      ShowCaptions = True
      TabOrder = 3
      Transparent = True
      Wrapable = False
      object ToolButton1: TToolButton
        Left = 10
        Top = 0
        Hint = 'ToolButton1'
        AutoSize = True
        Caption = 'Play Sound'
        ImageIndex = 0
        OnClick = ToolButton1Click
      end
      object ToolButton5: TToolButton
        Left = 132
        Top = 0
        Width = 8
        Caption = 'ToolButton5'
        ImageIndex = 5
        Style = tbsSeparator
      end
      object ToolButton2: TToolButton
        Left = 140
        Top = 0
        Hint = 'ToolButton2'
        Caption = 'Left'
        Down = True
        Grouped = True
        ImageIndex = 1
        Style = tbsCheck
        OnClick = ToolButton2Click
      end
      object ToolButton3: TToolButton
        Left = 266
        Top = 0
        Hint = 'ToolButton3'
        Caption = 'Center'
        Grouped = True
        ImageIndex = 2
        Style = tbsCheck
        OnClick = ToolButton3Click
      end
      object ToolButton4: TToolButton
        Left = 392
        Top = 0
        Hint = 'ToolButton4'
        Caption = 'Right'
        Grouped = True
        ImageIndex = 3
        Style = tbsCheck
        OnClick = ToolButton4Click
      end
    end
  end
  object ImageListNormal: TImageList
    BlendColor = clOlive
    DrawingStyle = dsTransparent
    Masked = False
    Left = 48
    Top = 88
    Bitmap = {...skipped...}
  end
  object ImageListHighlight: TImageList
    DrawingStyle = dsTransparent
    Left = 48
    Top = 144
    Bitmap = {...skipped...}
  end
end


Copyright Marco Cantù 1998