Marco Cantù 1998, Mastering Delphi 4
Project: CTRLMENU.DPR
Project Structure
CTRLMENU.DPR
program CtrlMenu;
uses
Forms,
CtrlForm in 'CtrlForm.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
CTRLFORM.PAS
unit CtrlForm;
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;
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.
CTRLFORM.DFM
object Form1: TForm1
Left = 206
Top = 127
Width = 671
Height = 392
Caption = 'CtrlMenu (Control Bar with Menu)'
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 = 56
Width = 663
Height = 309
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 ControlBar: TControlBar
Left = 0
Top = 0
Width = 663
Height = 56
Align = alTop
AutoDrag = False
AutoSize = True
DockSite = False
DragKind = dkDock
PopupMenu = PopupMenu1
RowSize = 25
RowSnap = False
TabOrder = 0
object ToolFontStyle: TToolBar
Left = 133
Top = 2
Width = 72
Height = 22
AutoSize = True
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 = 11
Top = 28
Width = 105
Height = 22
AutoSize = True
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 = 109
Height = 21
AutoSize = True
ButtonHeight = 21
ButtonWidth = 49
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 = 129
Top = 28
Width = 145
Height = 21
AutoSize = True
BevelOuter = bvNone
TabOrder = 3
object ComboFont: TComboBox
Left = 0
Top = 0
Width = 145
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 0
OnChange = ComboFontChange
end
end
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
0000000000000000000000000000FFFFFF000700FFFFFF070707FF00F8070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707F8FFFFFCFFFCFFFCFCF80000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000FF07FF070007FF0707070707F8F8FFFF0000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000F9FBF9FFFFFFF8FFFF0007FF07FF07FF0000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000007FF07F8FFFFFFFFFFFFFFFFF8FFF9F90000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707FF07FF07F8F8F8FFFFFF0000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000FFF9F9F907070700070707070707FF070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000FFFFFFFBF9FBF9FFFFFFFF00F80707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707F8FFFFFCFFFCFFFCFCF80000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000007FF07FF07FF0707070707070707F80000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000F8F8F8FFFFFFFF0007FF07FF07FF07FF0000
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000007FF07F8FFFFFFFFFFFFFFFFFFFFFFFF0000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707FF07FF07FF07FF07FF070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000FFFFFF0007070707070707070707FF070000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000707070707F8F8F8FF00F807070707070000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000070707070707F8FFFFFFFFFFFFFFFFFF0000
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
FFFF0000FFFFFFFFFFFFF800E01FF03FF00F0000E00FFCFFF00FF800F3CFFCFF
FFFFF800F3CFFCFFFC4F00F8F38FFE7FF80F0000F01FFE7FF91FF800F00FFE7F
F99F0000F3CFFF3FF99FF803F3CFFF3FF99FF800E00FFC0FF11FF803E01FFFFF
FFFF0000FFFFFFFFFFFF0003FFFFFFFFFFFF0000FFFFFFFFFFFF0100CFFF8001
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