|
The Form design, Mainform
Rename
the Form Form1.cs created and add new controls to it -
(New name - MainForm)
Classes used in this Form:
MainMenu, Timer, PictureBox, Label and StausBar
1- Rename the
Form
- On the View
menu , click Solution Explorer
- In Solution
Explorer, expand the App-VCSNet project node
and select Form1.cs
- In Properties
windows, Type the new File Name
|
Old |
New |
Filename : |
Form1.cs |
MainForm.cs | | |
|
1- Modify the Form Properties ...
- On the View
menu , click Solution Explorer
- In Solution
Explorer, expand the App-VCSNet project
node
- Right click the
MainForm.cs and click View Designer
on the shortcut menu to open the Properties
Windows.
- In Properties
windows, modify ...
|
Old |
New |
Name: FormBorderStyle Icon: Menu: Size: Text: Window
State: |
Form1 Sizable Icon (none) 300,300 Form1 Normal |
MainForm FixedSingle Icon
mainMenu1 630,500 Main
Form
... Maximized | | | |
- On the Project menu
, click App-VCSNet Properties ..., the App-VCSNet
Property Pages dialog box appears
- In the Startup
object combo box, choose and select
MainForm
- Click OK
|
Create
new Folder
- On the View
menu , click Solution Explorer
- In Solution
Explorer, expand the App-VCSNet project node,
click Right mouse Button, click Add of the
Popup menu, and the click New Folder
- New Folder
appears in the Solution Explorer. Rename it -
Pic
|
Add
Picture Files
- From the CD-Rom -
Teach_VNet, copy the bmp file
ingraphic1.bmp
(\\App-VCSNet\Pic\ingraphic1.bmp) to the
folder- c:\App-VCSNet\Pic
- From the CD-Rom -
Teach_VNet, copy the icon file
App-VCSNet.ico (\\App-VCSNet\Pic\App-VCSNet.ico)
to the folder - c:\App-VCSNet\Pic
- On the
Projet menu , click Add Existing Item
..., Add Existing Item - App-VCSNet dialog box
appears, select the files ingraphic1.bmp and
App-VCSNet.ico of the folder c:\App-VCSNet\Pic,
and then click Open.
| |
1- |
The MainForm.cs
design |
|
 |
2- |
From the Toolbox/Windows Form add these
controls ...
|
|
- Add the PictureBox
control - PictureBox1,
PictureBox Properties:
Name: Image: Size
Mode: |
PictureBox1 System.Drawing.Bitmap Autosize | |
Bitmap file
added =
C:\App-VCSNet\Pic\ingraphic1.bmp
- Add the Label
control
- Label1, Label
Properties:
Font: Name: Size: Text: TextAlign: |
Times New Roman, 9.75pt,
style=Bold, Italic Label1: 360,16 Learn
how to write Microsoft Visual C# .Net
application
... MiddleCenter | |
- Add the StatusBar
control - StatusBar1, StatusBar
Properties:
Name: Panels: Show
Panels: Size: Text: |
StatusBar1 (collection) True 804,16 StatusBar1 | |
The
StatusBarPanel Collection Editor dialog box
stores info about the panels added to this
control. StatusBarPanel
Properties ....
Name |
Alignment |
AutoSize |
Text |
ToolTipText |
Width |
StatusBarPanel1 StatusBarPanel2 StatusBarPanel3 |
left center center |
None Spring Spring |
none - - |
Status... Date
... Time ... |
200 200
200 | |
- Add the Timer
control
- Timer1,
Timer Properties:
Name: Enabled: Interval: |
Timer1 True 100 | |
- Add the MainMenu
control, MainMenu1
The
MainMenu control represents the container for
the menu structure of a form. A menu is composed of
MenuItem objects that represent the individual menu
commands in the menu structure. Each MenuItem
can be a command for your application or a parent menu
for other submenu items.
Add to this menu - MainMenu1 the
following items menu
Item |
Name |
Text |
0 1 2 3 4 5 |
MenuItem1 MenuItem2 MenuItem3 MenuItem4 MenuItem5 MenuItem6 |
Info
Menu Book - About - Exit |
The menu
design
...
| | | |
|
How create Public Event
in Visual C# .Net
MainForm.cs file, the code
...
The text
Code
is red color, corresponding to Load data in the Statusbar
control The text Code is Navy
color,
corresponding to Run the Form BookForm.cs The
text
Code is Maroon color, corresponding to Run
the Form About.cs |
|
using
System; using
System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace App_VCSNet
{
///
<summary>
///
Summary description for Form1.
///
</summary>
public
class
MainForm : System.Windows.Forms.Form
{
public
System.Windows.Forms.StatusBar statusBar1;
public
System.Windows.Forms.StatusBarPanel statusBarPanel1;
public
System.Windows.Forms.StatusBarPanel statusBarPanel2;
public
System.Windows.Forms.StatusBarPanel statusBarPanel3;
private
System.Windows.Forms.Label label1;
private
System.Windows.Forms.Timer timer1;
private
System.Windows.Forms.PictureBox pictureBox1;
private
System.Windows.Forms.MainMenu mainMenu1;
private
System.Windows.Forms.MenuItem menuItem1;
private
System.Windows.Forms.MenuItem menuItem2;
private
System.Windows.Forms.MenuItem menuItem3;
private
System.Windows.Forms.MenuItem menuItem4;
private
System.Windows.Forms.MenuItem menuItem5;
private
System.Windows.Forms.MenuItem menuItem6;
private
System.ComponentModel.IContainer components;
public
MainForm()
{
//
// Required for
Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any
constructor code after InitializeComponent call
//
}
///
<summary>
///
Clean up any resources being used.
///
</summary>
protected
override
void
Dispose( bool
disposing )
{
if(
disposing )
{
if
(components != null)
{
components.Dispose();
}
}
base.Dispose(
disposing );
}
#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>
private
void
InitializeComponent()
{
this.components
= new
System.ComponentModel.Container();
System.Resources.ResourceManager resources =
new
System.Resources.ResourceManager(typeof(MainForm));
this.statusBar1
= new
System.Windows.Forms.StatusBar();
this.statusBarPanel1
= new
System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2
= new
System.Windows.Forms.StatusBarPanel();
this.statusBarPanel3
= new
System.Windows.Forms.StatusBarPanel();
this.label1
= new
System.Windows.Forms.Label();
this.timer1
= new
System.Windows.Forms.Timer(this.components);
this.pictureBox1
= new
System.Windows.Forms.PictureBox();
this.mainMenu1
= new
System.Windows.Forms.MainMenu();
this.menuItem1
= new
System.Windows.Forms.MenuItem();
this.menuItem2
= new
System.Windows.Forms.MenuItem();
this.menuItem3
= new
System.Windows.Forms.MenuItem();
this.menuItem4
= new
System.Windows.Forms.MenuItem();
this.menuItem5
= new
System.Windows.Forms.MenuItem();
this.menuItem6
= new
System.Windows.Forms.MenuItem();
((System.ComponentModel.ISupportInitialize)( this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)( this.statusBarPanel2)).BeginInit();
((System.ComponentModel.ISupportInitialize)( this.statusBarPanel3)).BeginInit();
this.SuspendLayout();
//
// statusBar1
//
this.statusBar1.Location
= new
System.Drawing.Point(0, 389);
this.statusBar1.Name
= "statusBar1";
this.statusBar1.Panels.AddRange(new
System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3});
this.statusBar1.ShowPanels
= true;
this.statusBar1.Size
= new
System.Drawing.Size(624, 22);
this.statusBar1.TabIndex
= 5;
//
//
statusBarPanel1
//
this.statusBarPanel1.Text
= "none ";
this.statusBarPanel1.ToolTipText
= "Status ...";
this.statusBarPanel1.Width
= 300;
//
//
statusBarPanel2
//
this.statusBarPanel2.Alignment
= System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel2.ToolTipText
= "Date";
this.statusBarPanel2.Width
= 90;
//
//
statusBarPanel3
//
this.statusBarPanel3.Alignment
= System.Windows.Forms.HorizontalAlignment.Center;
this.statusBarPanel3.ToolTipText
= "Time ...";
this.statusBarPanel3.Width
= 90;
//
// label1
//
this.label1.Font
= new
System.Drawing.Font("Microsoft Sans Serif", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold
| System.Drawing.FontStyle.Italic))),
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location
= new
System.Drawing.Point(136, 288);
this.label1.Name
= "label1";
this.label1.Size
= new
System.Drawing.Size(376, 16);
this.label1.TabIndex
= 4;
this.label1.Text
= "Learn how to write Microsoft Visual C# .Net application
...";
this.label1.TextAlign
= System.Drawing.ContentAlignment.MiddleCenter;
//
// timer1
//
this.timer1.Enabled
= true;
this.timer1.Tick
+= new
System.EventHandler(this.timer1_Tick);
//
// pictureBox1
//
this.pictureBox1.BorderStyle
= System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox1.Image
= ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location
= new
System.Drawing.Point(120, 40);
this.pictureBox1.Name
= "pictureBox1";
this.pictureBox1.Size
= new
System.Drawing.Size(375, 199);
this.pictureBox1.SizeMode
= System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex
= 6;
this.pictureBox1.TabStop
= false;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index
= 0;
this.menuItem1.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuItem6});
this.menuItem1.Text
= "Main Menu";
//
// menuItem2
//
this.menuItem2.Index
= 0;
this.menuItem2.Text
= "Book";
this.menuItem2.Click
+= new
System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index
= 1;
this.menuItem3.Text
= "-";
//
// menuItem4
//
this.menuItem4.Index
= 2;
this.menuItem4.Text
= "About";
this.menuItem4.Click
+= new
System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index
= 3;
this.menuItem5.Text
= "-";
//
// menuItem6
//
this.menuItem6.Index
= 4;
this.menuItem6.Text
= "Exit";
this.menuItem6.Click
+= new
System.EventHandler(this.menuItem6_Click);
//
// MainForm
//
this.AutoScaleBaseSize
= new
System.Drawing.Size(5, 13);
this.ClientSize
= new
System.Drawing.Size(624, 411);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.statusBar1);
this.FormBorderStyle
= System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon
= ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox
= false;
this.Menu
= this.mainMenu1;
this.Name
= "MainForm";
this.Text
= "Main Form";
this.WindowState
= System.Windows.Forms.FormWindowState.Maximized;
this.Closing
+= new
System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.Load
+= new
System.EventHandler(this.MainForm_Load);
((System.ComponentModel.ISupportInitialize)( this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)( this.statusBarPanel2)).EndInit();
((System.ComponentModel.ISupportInitialize)( this.statusBarPanel3)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
<summary>
///
The main entry point for the application.
///
</summary>
[STAThread]
static
void
Main()
{
Application.Run( new
MainForm());
}
private
void
MainForm_Load(object
sender, System.EventArgs e)
{
// Resize ...
// PictureBox
control
this.pictureBox1.Left
= ((this.Width
- this.pictureBox1.Width)
/ 2);
this.pictureBox1.Top
= this.Height
/ 4;
//
this.pictureBox1.Image = System.Drawing.Image.FromFile("G:\App\App-VCSNet
C#\pic\ingraphic1.bmp");
// Label control
this.label1.Width
= this.Width
- 100;
this.label1.Left
= (this.Width
- this.label1.Width)
/ 2;
this.label1.Top
= this.Height
* 3 / 4;
this.statusBarPanel1.Width
= (this.Width
* 3)/8;
this.statusBarPanel2.Width
= this.Width
* 3/ 8;
this.statusBarPanel3.Width
= this.Width
* 2 / 8;
// StatusBar
Panel 1, Message ...
this.statusBarPanel1.Text
= "Hello ...";
//
StatusBarPanel2, Date ...
this.statusBarPanel2.Text
= DateTime.Now.ToLongDateString();
}
private
void
menuItem2_Click(object
sender, System.EventArgs e)
{
BookForm Fbook =
new
BookForm();
// StatusBar
Panel 1 = Message
this.statusBarPanel1.Text
= "Book Form, moment ...";
Fbook.Show();
}
private
void
menuItem4_Click(object
sender, System.EventArgs e)
{
About Fabout =
new
About();
// StatusBar
Panel 1 = Message
this.statusBarPanel1.Text
= "About Form, moment ...";
Fabout.Show();
}
private
void
menuItem6_Click(object
sender, System.EventArgs e)
{
Application.Exit();
}
private
void
timer1_Tick(object
sender, System.EventArgs e)
{
//
StatusBarPanel3, Time ...
this.statusBarPanel3.Text
= DateTime.Now.ToLongTimeString();
}
private
void
MainForm_Closing(object
sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
}
} | | |
|
|