Marco Cantù 1998, Mastering Delphi 4
Project: DOCKBAR.DPR
Project Structure
DOCKBAR.DPR
program DockBar;
uses
Forms,
DockForm in 'DockForm.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
DOCKFORM.PAS
unit DockForm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, StdCtrls, ExtCtrls, Menus, ComCtrls, ToolWin, ImgList, ActnList;
type
TForm1 = class(TForm)
ControlBar: TControlBar;
Label1: TLabel;
ImageList1: TImageList;
ToolFontStyle: TToolBar;
tbBold: TToolButton;
tbitalic: TToolButton;
tbUnderline: TToolButton;
ToolAlign: TToolBar;
tbNote: TToolButton;
ToolButton9: TToolButton;
tbLeft: TToolButton;
tbCenter: TToolButton;
tbRight: TToolButton;
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
Toolbar1: TMenuItem;
Visible1: TMenuItem;
DisableSound1: TMenuItem;
DisableStyles1: TMenuItem;
Help1: TMenuItem;
AboutToolbar1: TMenuItem;
PopupMenu1: TPopupMenu;
Hide1: TMenuItem;
N1: TMenuItem;
DisableSound2: TMenuItem;
DisableStyles2: TMenuItem;
ActionList1: TActionList;
actVisible: TAction;
actDisableSound: TAction;
actDisableStyles: TAction;
actExit: TAction;
ToolMenu: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Panel1: TPanel;
ComboFont: TComboBox;
ControlBar1: TControlBar;
procedure tbLeftClick(Sender: TObject);
procedure tbCenterClick(Sender: TObject);
procedure tbRightClick(Sender: TObject);
procedure tbNoteClick(Sender: TObject);
procedure tbBoldClick(Sender: TObject);
procedure tbitalicClick(Sender: TObject);
procedure tbUnderlineClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboFontChange(Sender: TObject);
procedure AboutToolbar1Click(Sender: TObject);
procedure actDisableSoundExecute(Sender: TObject);
procedure actDisableStylesExecute(Sender: TObject);
procedure actExitExecute(Sender: TObject);
procedure actVisibleExecute(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.tbLeftClick(Sender: TObject);
begin
Label1.Alignment := taLeftJustify;
end;
procedure TForm1.tbCenterClick(Sender: TObject);
begin
Label1.Alignment := taCenter;
end;
procedure TForm1.tbRightClick(Sender: TObject);
begin
Label1.Alignment := taRightJustify;
end;
procedure TForm1.tbNoteClick(Sender: TObject);
begin
Beep;
end;
procedure TForm1.tbBoldClick(Sender: TObject);
begin
with Label1.Font do
if fsBold in Style then
Style := Style - [fsBold]
else
Style := Style + [fsBold];
end;
procedure TForm1.tbitalicClick(Sender: TObject);
begin
with Label1.Font do
if fsItalic in Style then
Style := Style - [fsItalic]
else
Style := Style + [fsItalic];
end;
procedure TForm1.tbUnderlineClick(Sender: TObject);
begin
with Label1.Font do
if fsUnderline in Style then
Style := Style - [fsUnderline]
else
Style := Style + [fsUnderline];
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboFont.Items := Screen.Fonts;
ComboFont.ItemIndex :=
ComboFont.Items.IndexOf (Label1.Font.Name);
end;
procedure TForm1.ComboFontChange(Sender: TObject);
begin
Label1.Font.Name := ComboFont.Text;
end;
procedure TForm1.AboutToolbar1Click(Sender: TObject);
begin
MessageDlg ('Toolbar example for "Mastering Delphi"' +
Chr (13) + 'Written by Marco Cantù',
mtInformation, [mbOk], 0);
end;
procedure TForm1.actDisableSoundExecute(Sender: TObject);
begin
// disable or enable button and set check mark
tbNote.Enabled := not tbNote.Enabled;
actDisableSound.Checked := not tbNote.Enabled;
end;
procedure TForm1.actDisableStylesExecute(Sender: TObject);
begin
ToolFontStyle.Visible := not ToolFontStyle.Visible;
actDisableStyles.Checked := ToolFontStyle.Visible;
end;
procedure TForm1.actExitExecute(Sender: TObject);
begin
Close;
end;
procedure TForm1.actVisibleExecute(Sender: TObject);
begin
// hide or display the toolbar, setting the checkmark
ToolAlign.Visible := not ToolAlign.Visible;
Visible1.Checked := ToolAlign.Visible;
end;
end.
DOCKFORM.DFM
object Form1: TForm1
Left = 206
Top = 127
Width = 671
Height = 392
Caption = 'DockBar (Dockable ToolBars)'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 0
Top = 30
Width = 663
Height = 277
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 = -19
Font.Name = 'Arial'
Font.Style = []
ParentFont = False
WordWrap = True
end
object ControlBar: TControlBar
Left = 0
Top = 0
Width = 663
Height = 30
Align = alTop
AutoSize = True
PopupMenu = PopupMenu1
RowSize = 25
RowSnap = False
TabOrder = 0
object ToolFontStyle: TToolBar
Left = 414
Top = 2
Width = 74
Height = 22
AutoSize = True
DragKind = dkDock
DragMode = dmAutomatic
EdgeBorders = []
EdgeInner = esNone
EdgeOuter = esNone
Flat = True
Images = ImageList1
TabOrder = 0
object tbBold: TToolButton
Left = 0
Top = 0
Caption = 'tbBold'
ImageIndex = 4
Style = tbsCheck
OnClick = tbBoldClick
end
object tbitalic: TToolButton
Left = 23
Top = 0
Caption = 'tbitalic'
ImageIndex = 5
Style = tbsCheck
OnClick = tbitalicClick
end
object tbUnderline: TToolButton
Left = 46
Top = 0
Caption = 'tbUnderline'
ImageIndex = 6
Style = tbsCheck
OnClick = tbUnderlineClick
end
end
object ToolAlign: TToolBar
Left = 300
Top = 2
Width = 101
Height = 22
AutoSize = True
DragKind = dkDock
DragMode = dmAutomatic
EdgeBorders = []
EdgeInner = esNone
EdgeOuter = esNone
Flat = True
Images = ImageList1
TabOrder = 1
object tbNote: TToolButton
Left = 0
Top = 0
Caption = 'ToolButton3'
ImageIndex = 0
OnClick = tbNoteClick
end
object ToolButton9: TToolButton
Left = 23
Top = 0
Width = 8
Caption = 'ToolButton6'
ImageIndex = 3
Style = tbsSeparator
end
object tbLeft: TToolButton
Left = 31
Top = 0
Caption = 'ToolButton4'
Grouped = True
ImageIndex = 1
OnClick = tbLeftClick
end
object tbCenter: TToolButton
Left = 54
Top = 0
Caption = 'ToolButton5'
Grouped = True
ImageIndex = 2
OnClick = tbCenterClick
end
object tbRight: TToolButton
Left = 77
Top = 0
Caption = 'ToolButton7'
Grouped = True
ImageIndex = 3
OnClick = tbRightClick
end
end
object ToolMenu: TToolBar
Left = 11
Top = 2
Width = 118
Height = 21
AutoSize = True
ButtonHeight = 21
ButtonWidth = 49
DragKind = dkDock
DragMode = dmAutomatic
EdgeBorders = []
Flat = True
ShowCaptions = True
TabOrder = 2
object ToolButton1: TToolButton
Left = 0
Top = 0
AutoSize = True
Caption = '&File'
MenuItem = File1
end
object ToolButton2: TToolButton
Left = 27
Top = 0
AutoSize = True
Caption = '&Toolbar'
MenuItem = Toolbar1
OnClick = actVisibleExecute
end
object ToolButton3: TToolButton
Left = 74
Top = 0
AutoSize = True
Caption = '&Help'
Grouped = True
MenuItem = Help1
end
end
object Panel1: TPanel
Left = 142
Top = 2
Width = 145
Height = 21
AutoSize = True
BevelOuter = bvNone
DragKind = dkDock
DragMode = dmAutomatic
TabOrder = 3
object ComboFont: TComboBox
Left = 0
Top = 0
Width = 145
Height = 21
Style = csDropDownList
DragKind = dkDock
ItemHeight = 13
TabOrder = 0
OnChange = ComboFontChange
end
end
end
object ControlBar1: TControlBar
Left = 0
Top = 307
Width = 663
Height = 58
Align = alBottom
AutoSize = True
BorderWidth = 1
TabOrder = 1
end
object ImageList1: TImageList
Left = 40
Top = 80
Bitmap = {
360C000007000000424D360C0000000000003604000028000000400000002000
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
000000000000000000000000000000FF07070707070700000707070000070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070007070707070707070007070707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070007070707070707070707070700070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707000707070707070707000707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070007070707070007070707F800FF070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070007070700070707070707070707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000707070707070007000007070007000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000707F800FF07070707070707070007070000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000007070707000000070707070707F8000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707070007070707070707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707000707070700070700070707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707070707070707070707070000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000FF07070707070700070707070700070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000707070707070707070007070707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070007070707070707070707070707000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707000707070707070707000707070000
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
FFFF03F8FFFFFFFFFFFFF8FFE01FF03FF00FFBFBE00FFCFFF00F0000F3CFFCFF
FFFF0000F3CFFCFFFC4FFBFBF38FFE7FF80FFFFBF01FFE7FF91FFBFBF00FFE7F
F99F00FFF3CFFF3FF99F0000F3CFFF3FF99F0000E00FFC0FF11F0000E01FFFFF
FFFF0000FFFFFFFFFFFF0000FFFFFFFFFFFF0000FFFFFFFFFFFF0001CFFF8001
80018001873FBFFDBFFDBFFD821FA03DB81DBC05C20FBFFDBFFDBFFDFB0FA3FD
BC3DBFC5FBEFBFFDBFFDBFFDFBEFA0FDB81DBF05FBEFBFFDBFFDBFFDFBEFA3FD
BE7DBFC5FBEFBFFDBFFDBFFDF8EFA01DB00DB805FB0FBFFDBFFDBFFDF8EFA07D
B81DBE05FF0FBFFDBFFDBFFDFFFF800180018001FFFFFFFFFFFFFFFF}
end
object MainMenu1: TMainMenu
Left = 40
Top = 136
object File1: TMenuItem
Caption = '&File'
object Exit1: TMenuItem
Caption = 'E&xit'
end
end
object Toolbar1: TMenuItem
Caption = '&Toolbar'
object Visible1: TMenuItem
Action = actVisible
end
object DisableSound1: TMenuItem
Action = actDisableSound
end
object DisableStyles1: TMenuItem
Action = actDisableStyles
end
end
object Help1: TMenuItem
Caption = '&Help'
object AboutToolbar1: TMenuItem
Caption = '&About Toolbar...'
OnClick = AboutToolbar1Click
end
end
end
object PopupMenu1: TPopupMenu
Left = 112
Top = 80
object Hide1: TMenuItem
Action = actVisible
Caption = '&Toolbar Visible'
end
object N1: TMenuItem
Caption = '-'
end
object DisableSound2: TMenuItem
Action = actDisableSound
Caption = 'Disable &Sound'
end
object DisableStyles2: TMenuItem
Action = actDisableStyles
end
end
object ActionList1: TActionList
Left = 112
Top = 136
object actVisible: TAction
Caption = 'Align &Visible'
ShortCut = 49238
OnExecute = actVisibleExecute
end
object actDisableSound: TAction
Caption = 'Disable &Sounds'
OnExecute = actDisableSoundExecute
end
object actDisableStyles: TAction
Caption = '&Hide Styles'
OnExecute = actDisableStylesExecute
end
object actExit: TAction
Caption = '&Exit'
ShortCut = 32883
OnExecute = actExitExecute
end
end
end
Copyright Marco Cantù 1998