|
1. Create
Delphi Windows Forms Application
On the File menu ,
click New. and then click Windows Forms
Application. New Project - Project1 and New File
name WinForm.pas appears.
Form created:
On the View menu , click Project Manager. In
Project Manager appears all components created ...
Project Manager :
Rename
the components created ...
On
the View menu , click Object Inspector. In Object
Inspector modify the following ...
1-
Project1 - Windows Forms Application created
|
Old |
New |
File Name: |
Project1.bdsproj |
App-WF.bdsproj | |
2-
WinForm.pas - the File name created
|
Old |
New |
File Name: |
WinForm.pas |
MainForm
.pas | |
3 -
TWinForm- Form name created
|
Old |
New |
Name: |
TWinForm |
TMainForm
| |
Details,
look: Modify the Properties of TWinForm
(WinForm.pas)
The codes
corresponding to the Windows Form created by system ....
File name -
WinForm.pas
unit WinForm;
interface
uses
System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data;
type
TWinForm = class(System.Windows.Forms.Form)
{$REGION 'Designer Managed Code'}
strict private
/// <summary>
/// Required designer variable.
/// </summary>
Components: System.ComponentModel.Container;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure InitializeComponent;
{$ENDREGION}
strict protected
/// <summary>
/// Clean up any resources being used.
/// </summary>
procedure Dispose(Disposing: Boolean); override;
private
{ Private Declarations }
public
constructor Create;
end;
[assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]
implementation
{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
Self.Components := System.ComponentModel.Container.Create;
Self.Size := System.Drawing.Size.Create(300, 300);
Self.Text := 'WinForm';
end;
{$ENDREGION}
procedure TWinForm.Dispose(Disposing: Boolean);
begin
if Disposing then
begin
if Components <> nil then
Components.Dispose();
end;
inherited Dispose(Disposing);
end;
constructor TWinForm.Create;
begin
inherited Create;
//
// Required for Windows Form Designer support
//
InitializeComponent;
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
end. |
2. TheWindows
Form
- Mainform, design
Classes used in this
Form: System.Drawing, System.Collections,
System.ComponentModel, System.Windows.Forms, System.Data, System.Resources,
Borland.Vcl.SysUtils ;
Type of Controls used in this
Form:
MainMenu, Timer, PictureBox, Label and StausBar
|
1- Modify the Properties of
TWinForm
(WinForm.pas)
- Modify TWinForm
(WinForm.pas) ,
On the View menu , click Object
Inspector. In Object Inspector
modify the following ...
-
|
Old |
New |
Caption: Name: Icon: Menu:
Maximizebox: StartPosition: Size: |
WinForm TWinForm (Icon) (none) True
WindowsDefaultLocation 300,300 |
MainForm Main_Form (Icon) (none) False
CenterScreen
592,502 | | | |
- In C:, Create the
Folder App-WFDelphi (C:\App-WFDelphi),
- On the File menu ,
click Save As, the Save Mainform As dialog box
appears... In this Folder
save Form - Mainform and Application App-WF
|
|
Add
the following Folder and Files
- From the File
download ..., copy the folder pic (stored
picture files and KJV2002.mdb) to the folder -
C:\App-WFDelpi
| |
1- |
The MainForm
design |
|
 |
2- |
From the Tool palette add these
controls ...
(From the View menu, click Tool
palette) |
|
- Add the PictureBox
control - PictureBox1, Object
inspector:
Name: Image SizeMode: Visible: |
PictureBox1 System.Drawing.Image...
AutoSixe True | |
Bitmap file
added =
C:\App-WFDelphi\Pic\ingraphic1.bmp
- Add the PictureBox
control - PictureA, Object
inspector:
Name: Image SizeMode: Visible: |
PictureA System.Drawing.Image...
AutoSixe False | |
Bitmap file
added =
C:\App-WFDelphi\Pic\butterfly1.bmp
- Add the PictureBox
control - PictureB, Object
inspector:
Name: Image SizeMode: Visible: |
PictureB System.Drawing.Image...
AutoSixe False | |
Bitmap file
added =
C:\App-WFDelphi\Pic\butterfly2.bmp
- Add the Label
control
- Label1, Object
inspector:
:
Font: Name: Text: TextAlign: |
Times New Roman, 9.75pt,
style=Bold, Italic Label1 Learn how to
write Windows Forms Delphi 8 application ...
MiddleCenter | |
- Add the StatusBar
control - StatusBar1, Object
inspector:
:
Name: Panels: |
StatusBar1 (Collection) | |
The
StatusBarPanel Collection
Editor..,
Object inspector:
Name |
Alignment |
Width |
StatusBarPanel1 StatusBarPanel2
StatusBarPanel3 |
Left Center Center |
200 200 200 | |
- Add the Timer
control
- Timer1, Object
inspector:
Enabled: Interval: Name: |
True 100 Timer1 | |
- Add the Timer
control
- Timer2, Object
inspector:
Enabled: Interval: Name: |
True 100 Timer2 | |
- Add the MainMenu
control, MainMenu1, Object
inspector:
Add to this menu - MainMenu1 the
following items menu
Item |
Name |
Text |
0 1 2 3 4 5 |
MMainMenu MBook MenuItem3
MAbout MenuItem5 MExit |
Main
Menu Book - About - Exit |
The menu
design
...
| | | |
|
The
Event and codes in Delphi
...
The text Code is Navy
color,
corresponding to code create by system The text Code is
red color, corresponding to the code corresponding to the
events added The text Code is Navy
color,
corresponding to the other form to be
add |
|
App-WF, the
code |
program App_WF;
{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.dll'}
{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Data.dll'}
{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Drawing.dll'}
{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.Windows.Forms.dll'}
{%DelphiDotNetAssemblyCompiler '$(SystemRoot)\microsoft.net\framework\v1.1.4322\System.XML.dll'}
{$R 'MainForm.TMainForm.resources' 'MainForm.resx'}
{$R 'About.TAbout.resources' 'About.resx'}
{$R 'Book.TBook.resources' 'Book.resx'}
{%ConfigurationCompiler 'app1.config'}
{%XsdCompiler 'BDataSet.xsd'}
uses
System.Reflection,
System.Runtime.CompilerServices,
System.Windows.Forms,
MainForm in 'MainForm.pas' {MainForm.TMainForm:
System.Windows.Forms.Form},
About in 'About.pas' {About.TAbout:
System.Windows.Forms.Form},
Book in 'Book.pas' {Book.TBook:
System.Windows.Forms.Form},
BDataSetUnit in 'BDataSetUnit.pas';
{$R *.res}
{$REGION 'Program/Assembly Information'}
//
// General Information about an assembly is
controlled through the following
// set of attributes. Change these attribute
values to modify the information
// associated with an assembly.
//
[assembly: AssemblyDescription('')]
[assembly: AssemblyConfiguration('')]
[assembly: AssemblyCompany('')]
[assembly: AssemblyProduct('')]
[assembly: AssemblyCopyright('')]
[assembly: AssemblyTrademark('')]
[assembly: AssemblyCulture('')]
// The Delphi compiler controls the
AssemblyTitleAttribute via the ExeDescription.
// You can set this in the IDE via the Project
Options.
// Manually setting the AssemblyTitle attribute
below will override the IDE
// setting.
// [assembly: AssemblyTitle('')]
//
// Version information for an assembly consists
of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can
default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion('1.0.*')]
//
// In order to sign your assembly you must
specify a key to use. Refer to the
// Microsoft .NET Framework documentation for
more information on assembly signing.
//
// Use the attributes below to control which key
is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is
not signed.
// (*) KeyName refers to a key that has been
installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile
refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are
both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP,
that key is used.
// (2) If the KeyName does not exist and the
KeyFile does exist, the key
// in the KeyFile is installed into the CSP and
used.
// (*) In order to create a KeyFile, you can use
the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of
the KeyFile should be
// relative to the project output directory. For
example, if your KeyFile is
// located in the project directory, you would
specify the AssemblyKeyFile
// attribute as [assembly:
AssemblyKeyFile('mykey.snk')], provided your
output
// directory is the project directory (the
default).
// (*) Delay Signing is an advanced option - see
the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile('')]
[assembly: AssemblyKeyName('')]
{$ENDREGION}
[STAThread]
begin
Application.Run(TMainForm.Create);
end. | |
|
Mainform, the
code |
unit MainForm;
interface
uses
System.Drawing, System.Collections,
System.ComponentModel,
System.Windows.Forms, System.Data,
System.Resources, Borland.Vcl.SysUtils ;
type
TMainForm = class(System.Windows.Forms.Form)
{$REGION 'Designer Managed Code'}
strict private
/// <summary>
/// Required designer variable.
/// </summary>
components: System.ComponentModel.IContainer;
MainMenu1: System.Windows.Forms.MainMenu;
MMainMenu: System.Windows.Forms.MenuItem;
MBook: System.Windows.Forms.MenuItem;
MenuItem3: System.Windows.Forms.MenuItem;
MAbout: System.Windows.Forms.MenuItem;
MenuItem5: System.Windows.Forms.MenuItem;
MExit: System.Windows.Forms.MenuItem;
PictureBox1: System.Windows.Forms.PictureBox;
Label1: System.Windows.Forms.Label;
PictureA: System.Windows.Forms.PictureBox;
PictureB: System.Windows.Forms.PictureBox;
StatusBar1: System.Windows.Forms.StatusBar;
StatusBarPanel1:
System.Windows.Forms.StatusBarPanel;
StatusBarPanel2:
System.Windows.Forms.StatusBarPanel;
StatusBarPanel3:
System.Windows.Forms.StatusBarPanel;
Timer1: System.Windows.Forms.Timer;
Timer2: System.Windows.Forms.Timer;
/// <summary>
/// Required method for Designer support - do
not modify
/// the contents of this method with the code
editor.
/// </summary>
procedure InitializeComponent;
procedure Timer1_Tick(sender: System.Object; e:
System.EventArgs);
procedure MBook_Click(sender: System.Object; e:
System.EventArgs);
procedure MAbout_Click(sender: System.Object; e:
System.EventArgs);
procedure MExit_Click(sender: System.Object; e:
System.EventArgs);
procedure Timer2_Tick(sender: System.Object; e:
System.EventArgs);
{$ENDREGION}
strict protected
/// <summary>
/// Clean up any resources being used.
/// </summary>
procedure Dispose(Disposing: Boolean); override;
private
{ Private Declarations }
public
// Public, StatusBarPanel1 value
class function SetStatus : string;
// Public, Current Directory name
class Function DataDirectory : string;
constructor Create;
end;
[assembly:
RuntimeRequiredAttribute(TypeOf(TMainForm))]
implementation
uses
About, Book;
var
kk : integer;
{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do
not modify
/// the contents of this method with the code
editor.
/// </summary>
procedure TMainForm.InitializeComponent;
type
TSystem_Windows_Forms_MenuItemArray = array of
System.Windows.Forms.MenuItem;
TSystem_Windows_Forms_StatusBarPanelArray =
array of System.Windows.Forms.StatusBarPanel;
var
resources: System.Resources.ResourceManager;
begin
Self.components :=
System.ComponentModel.Container.Create;
resources :=
System.Resources.ResourceManager.Create(TypeOf(TMainForm));
Self.MainMenu1 :=
System.Windows.Forms.MainMenu.Create;
Self.MMainMenu :=
System.Windows.Forms.MenuItem.Create;
Self.MBook :=
System.Windows.Forms.MenuItem.Create;
Self.MenuItem3 :=
System.Windows.Forms.MenuItem.Create;
Self.MAbout :=
System.Windows.Forms.MenuItem.Create;
Self.MenuItem5 :=
System.Windows.Forms.MenuItem.Create;
Self.MExit :=
System.Windows.Forms.MenuItem.Create;
Self.PictureBox1 :=
System.Windows.Forms.PictureBox.Create;
Self.Label1 := System.Windows.Forms.Label.Create;
Self.PictureA :=
System.Windows.Forms.PictureBox.Create;
Self.PictureB :=
System.Windows.Forms.PictureBox.Create;
Self.StatusBar1 :=
System.Windows.Forms.StatusBar.Create;
Self.StatusBarPanel1 :=
System.Windows.Forms.StatusBarPanel.Create;
Self.StatusBarPanel2 :=
System.Windows.Forms.StatusBarPanel.Create;
Self.StatusBarPanel3 :=
System.Windows.Forms.StatusBarPanel.Create;
Self.Timer1 :=
System.Windows.Forms.Timer.Create(Self.components);
Self.Timer2 :=
System.Windows.Forms.Timer.Create(Self.components);
(System.ComponentModel.ISupportInitialize(Self.StatusBarPanel1)).BeginInit;
(System.ComponentModel.ISupportInitialize(Self.StatusBarPanel2)).BeginInit;
(System.ComponentModel.ISupportInitialize(Self.StatusBarPanel3)).BeginInit;
Self.SuspendLayout;
//
// MainMenu1
//
Self.MainMenu1.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MMainMenu));
//
// MMainMenu
//
Self.MMainMenu.Index := 0;
Self.MMainMenu.MenuItems.AddRange(TSystem_Windows_Forms_MenuItemArray.Create(Self.MBook,
Self.MenuItem3, Self.MAbout, Self.MenuItem5,
Self.MExit));
Self.MMainMenu.Text := 'Main Menu';
//
// MBook
//
Self.MBook.Index := 0;
Self.MBook.Text := 'Book';
Include(Self.MBook.Click, Self.MBook_Click);
//
// MenuItem3
//
Self.MenuItem3.Index := 1;
Self.MenuItem3.Text := '-';
//
// MAbout
//
Self.MAbout.Index := 2;
Self.MAbout.Text := 'About';
Include(Self.MAbout.Click, Self.MAbout_Click);
//
// MenuItem5
//
Self.MenuItem5.Index := 3;
Self.MenuItem5.Text := '-';
//
// MExit
//
Self.MExit.Index := 4;
Self.MExit.Text := 'Exit';
Include(Self.MExit.Click, Self.MExit_Click);
//
// PictureBox1
//
Self.PictureBox1.Image := (System.Drawing.Image(resources.GetObject('PictureBox1.Image')));
Self.PictureBox1.Location :=
System.Drawing.Point.Create(120, 80);
Self.PictureBox1.Name := 'PictureBox1';
Self.PictureBox1.Size :=
System.Drawing.Size.Create(375, 199);
Self.PictureBox1.SizeMode :=
System.Windows.Forms.PictureBoxSizeMode.AutoSize;
Self.PictureBox1.TabIndex := 0;
Self.PictureBox1.TabStop := False;
//
// Label1
//
Self.Label1.Font :=
System.Drawing.Font.Create('Times New Roman',
9.75, (System.Drawing.FontStyle((System.Drawing.FontStyle.Bold
or System.Drawing.FontStyle.Italic))),
System.Drawing.GraphicsUnit.Point,
(Byte(178)));
Self.Label1.Location :=
System.Drawing.Point.Create(120, 288);
Self.Label1.Name := 'Label1';
Self.Label1.Size :=
System.Drawing.Size.Create(376, 24);
Self.Label1.TabIndex := 1;
Self.Label1.Text := 'Learn how to write Windows
Forms Delphi 8 application ...';
Self.Label1.TextAlign :=
System.Drawing.ContentAlignment.MiddleCenter;
//
// PictureA
//
Self.PictureA.Image := (System.Drawing.Image(resources.GetObject('PictureA.Image')));
Self.PictureA.Location :=
System.Drawing.Point.Create(248, 328);
Self.PictureA.Name := 'PictureA';
Self.PictureA.Size :=
System.Drawing.Size.Create(77, 77);
Self.PictureA.SizeMode :=
System.Windows.Forms.PictureBoxSizeMode.AutoSize;
Self.PictureA.TabIndex := 2;
Self.PictureA.TabStop := False;
//
// PictureB
//
Self.PictureB.Image := (System.Drawing.Image(resources.GetObject('PictureB.Image')));
Self.PictureB.Location :=
System.Drawing.Point.Create(344, 328);
Self.PictureB.Name := 'PictureB';
Self.PictureB.Size :=
System.Drawing.Size.Create(77, 77);
Self.PictureB.SizeMode :=
System.Windows.Forms.PictureBoxSizeMode.AutoSize;
Self.PictureB.TabIndex := 3;
Self.PictureB.TabStop := False;
//
// StatusBar1
//
Self.StatusBar1.Font :=
System.Drawing.Font.Create('Times New Roman', 9,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, (Byte(178)));
Self.StatusBar1.Location :=
System.Drawing.Point.Create(0, 428);
Self.StatusBar1.Name := 'StatusBar1';
Self.StatusBar1.Panels.AddRange(TSystem_Windows_Forms_StatusBarPanelArray.Create(Self.StatusBarPanel1,
Self.StatusBarPanel2, Self.StatusBarPanel3));
Self.StatusBar1.ShowPanels := True;
Self.StatusBar1.Size :=
System.Drawing.Size.Create(584, 22);
Self.StatusBar1.TabIndex := 4;
Self.StatusBar1.Text := 'StatusBar1';
//
// StatusBarPanel1
//
Self.StatusBarPanel1.AutoSize :=
System.Windows.Forms.StatusBarPanelAutoSize.Spring;
Self.StatusBarPanel1.Text := 'StatusBarPanel1';
Self.StatusBarPanel1.Width := 189;
//
// StatusBarPanel2
//
Self.StatusBarPanel2.Alignment :=
System.Windows.Forms.HorizontalAlignment.Center;
Self.StatusBarPanel2.AutoSize :=
System.Windows.Forms.StatusBarPanelAutoSize.Spring;
Self.StatusBarPanel2.Text := 'StatusBarPanel2';
Self.StatusBarPanel2.Width := 189;
//
// StatusBarPanel3
//
Self.StatusBarPanel3.Alignment :=
System.Windows.Forms.HorizontalAlignment.Center;
Self.StatusBarPanel3.AutoSize :=
System.Windows.Forms.StatusBarPanelAutoSize.Spring;
Self.StatusBarPanel3.Text := 'StatusBarPanel3';
Self.StatusBarPanel3.Width := 189;
//
// Timer1
//
Self.Timer1.Enabled := True;
Include(Self.Timer1.Tick, Self.Timer1_Tick);
//
// Timer2
//
Self.Timer2.Enabled := True;
Include(Self.Timer2.Tick, Self.Timer2_Tick);
//
// TMainForm
//
Self.AutoScaleBaseSize :=
System.Drawing.Size.Create(5, 13);
Self.ClientSize :=
System.Drawing.Size.Create(584, 450);
Self.Controls.Add(Self.StatusBar1);
Self.Controls.Add(Self.PictureB);
Self.Controls.Add(Self.PictureA);
Self.Controls.Add(Self.Label1);
Self.Controls.Add(Self.PictureBox1);
Self.Icon := (System.Drawing.Icon(resources.GetObject('$this.Icon')));
Self.MaximizeBox := False;
Self.Menu := Self.MainMenu1;
Self.Name := 'TMainForm';
Self.StartPosition :=
System.Windows.Forms.FormStartPosition.CenterScreen;
Self.Text := 'Main Form';
(System.ComponentModel.ISupportInitialize(Self.StatusBarPanel1)).EndInit;
(System.ComponentModel.ISupportInitialize(Self.StatusBarPanel2)).EndInit;
(System.ComponentModel.ISupportInitialize(Self.StatusBarPanel3)).EndInit;
Self.ResumeLayout(False);
end;
{$ENDREGION}
procedure TMainForm.Dispose(Disposing: Boolean);
begin
if Disposing then
begin
if Components <> nil then
Components.Dispose();
end;
inherited Dispose(Disposing);
end;
constructor TMainForm.Create;
begin
inherited Create;
//
// Required for Windows Form Designer support
//
InitializeComponent;
//
// TODO: Add any constructor code after
InitializeComponent call
//
// Resize ...
// Image control
self.PictureBox1.Left := ((self.Width -
self.PictureBox1.Width) div 2);
self.PictureBox1.Top := self.Height div 7;
self.PictureA.Left := ((self.Width -
self.PictureA.Width) div 2);
// Label control
self.label1.Width := self.Width - 100;
self.label1.Left := (self.Width -
self.label1.Width) div 2;
self.label1.Top := (self.Height * 3) div 5;
self.StatusBarPanel1.Width := (self.Width div 3
);
self.StatusBarPanel2.Width := (self.Width div 3
);
self.StatusBarPanel3.Width := (self.Width div 3
);
// Pictures values ...
self.PictureBox1.Image :=
System.Drawing.Image.FromFile(DataDirectory +
'ingraphic1.bmp');
self.PictureA.Image :=
System.Drawing.Image.FromFile(DataDirectory +
'butterfly1.bmp');
self.PictureB.Image :=
System.Drawing.Image.FromFile(DataDirectory +
'butterfly2.bmp');
// StatusBar Panel 1, Message ...
self.StatusBarPanel1.Text := 'Hello ...';
// StatusBar Panel 2, Date ...
self.StatusBarPanel2.Text :=
DateTime.get_Now.ToLongDateString();
kk := 1;
end;
class Function TMainForm.DataDirectory : string;
begin
// current directory stored KJV22002.mdb + other
pictures
Result :=
ExpandFileName(ExtractFilePath(ParamStr(0)) + '\pic\');
end;
procedure TMainForm.MBook_Click(sender:
System.Object; e: System.EventArgs);
begin
// StatusBar Panel 1 = Message
self.StatusBarPanel1.Text := 'Book Form, moment
...';
TBook.Showbook;
end;
procedure TMainForm.MAbout_Click(sender:
System.Object; e: System.EventArgs);
begin
// StatusBar Panel 1 = Message
self.StatusBarPanel1.Text := 'About Form, moment
...';
TAbout.ShowAbout;
end;
procedure TMainForm.MExit_Click(sender:
System.Object; e: System.EventArgs);
begin
// Application.Exit();
close;
end;
procedure TMainForm.Timer1_Tick(sender:
System.Object; e: System.EventArgs);
begin
// StatusBar Panel 3, Time ...
self.StatusBarPanel3.Text :=
DateTime.Now.ToLongTimeString();
// StatusBar Panel 1, Time ...
self.StatusBarPanel1.Text := SetStatus;
end;
procedure TMainForm.Timer2_Tick(sender:
System.Object; e: System.EventArgs);
begin
// StatusBar Panel 3, Time ...
self.StatusBarPanel3.Text :=
DateTime.Now.ToLongTimeString();
// Animation ....
if kk = 1 then
begin
self.PictureA.Visible := True;
self.PictureB.Visible := false;
end
else if kk = 2 then
begin
self.PictureB.Left := self.PictureA.Left;
self.PictureB.Top := self.PictureA.Top;
self.PictureB.Visible := True;
self.PictureA.Visible := false;
kk := 0;
end;
kk := kk + 1;
end;
class function TMainForm.SetStatus : string;
begin
Result := 'Ready ...'
end;
end. | |
| | | |
|
|