Академический Документы
Профессиональный Документы
Культура Документы
Net
Prepared by: Mr. Rogelio V. del Cano
Estimated Duration: 6 hours
Objectives:
Part I
MDI Children forms Windows
Create MDI
Rename Form1 as mdiMain Change its icon (select any icon related to sales and inventory system) Set IsMdiContainer to True Change Text property to: Main Menu Change WindowState to: Maximized
001 Introduction to MDI in C#.Net 4
3.
4.
5.
6.
Click Project, Add Windows Form Type frmCustomer.cs Change its BackColor to: Red Change its Icon (#39) Change its Size to: 608, 605 Change its Text to: Customer
001 Introduction to MDI in C#.Net 5
3.
4.
5.
6.
Click Project, Add Windows Form Type frmProduct.cs Change its BackColor to Green Change its Icon (#32) Change its Size to: 608, 605 Change its Text to: Product
001 Introduction to MDI in C#.Net 6
Click Project, Add Windows Form Type frmSupplier.cs Change its BackColor to Blue Change its Icon (#27) Change its Size to: 608, 605 Change its Text to: Supplier
001 Introduction to MDI in C#.Net 7
Go back to mdiMain, Designer View Double-click menuStrip from the ToolBox Rename it to menuStripMain Click Type Here from the mdiMain Type &File Maintenance then press the enter key Type &Customer then enter Type &Product then enter Type &Supplier then enter Type (hyphen) then enter Type &Hide then enter Type (hyphen) then enter Type &Relog Type &Logout Type (hyphen) then enter Type E&xit then enter
Note: You are freeIntroduction to MDI inadd more images. 001 to change or C#.Net
Note: You are freeIntroduction to MDI inadd more images. 001 to change or C#.Net
10
Note: You are freeIntroduction to MDI inadd more images. 001 to change or C#.Net
11
Note: You are freeIntroduction to MDI inadd more images. 001 to change or C#.Net
12
Customer Ctrl+F1
13
14
15
Click the Type Here beside the File Maintenance pull down menu Type &Window, then press the enter key Type &Cascade then enter Type &Horizontal then enter Type &Vertical then enter Type &Arrange
001 Introduction to MDI in C#.Net 16
File Maintenance fileMaintenanceToolStripMenuItem Customer customerToolStripMenuItem Product productToolStripMenuItem Supplier supplierToolStripMenuItem Hide hideToolStripMenuItem Relog relogToolStripMenuItem Logout logoutToolStripMenuItem Exit exitToolStripMenuItem
17
Window windowToolStripMenuItem
18
Double-click the Customer tool strip menu item from the File Maintenance pull down menu Type the following codes:
1.
2. 3.
Double-click the Product tool strip menu item from the File Maintenance pull down menu Type the following codes:
20
Double-click the Supplier tool strip menu item from the File Maintenance pull down menu Type the following codes:
Press F5 to run your program Click the File pull down menu Display the following forms
23
24
Cascaded Forms
Double-click the Cascade menu item from the mdiMain In the Code Window type:
this.LayoutMdi(MdiLayout.Cascade);
25
Horizontal Forms
Double-click the Horizontal menu item from the mdiMain In the Code Window type:
this.LayoutMdi(MdiLayout.TileHorizontal);
26
Vertical Forms
Double-click the Vertical menu item from the mdiMain In the Code Window type:
this.LayoutMdi(MdiLayout.TileVertical);
27
Double-click the Arrange menu item from the mdiMain In the Code Window type:
this.LayoutMdi(MdiLayout.ArrangeIcons);
28
29
30
Go back to the designer view Add a StatusStrip by doubleclicking the same from the ToolBox On the Properties Window, change its name to statusStripMain
Note: You may also click the001 Introduction toobject from the object container. status strip MDI in C#.Net
31
Click Items from the Properties Window Click its ellipsis Click Add Change its Text property to: College of Saint Benilde
32
Click once more the Add button Set the Spring property to: True Delete the contents of the Text property
33
Click again the Add button Rename it to: toolStripStatusLabelUsername Delete the contents of the Text property Note: This tool strip will be used in Advanced Programming
34
Click again the Add button Rename it to: toolStripStatusLabelUserLevel Delete the contents of the Text property Note: This tool strip will be used in Advanced Programming
35
Click again the Add button Rename it to: toolStripStatusLabelDate Change the Text property to: Date
36
Click again the Add button Rename it to: toolStripStatusLabelTime Change the BackColor property to: Khaki (or any color) Add icon to the Image property. Select any clock picture. Change the Text property to: Time
37
statusStrip Output
Click the Okay button See the picture below as the final output of your status strip.
Add a Timer
Double-click Timer from the ToolBox Change its name to tmrTime Set Enabled to True Set Interval to 1000
39
Go back to the mdiMain Double-click the form to view the Code Window Immediately, youll see the Load Event From the Load Event, type
//Local Date and Time this. toolStripStatusLabelDate.Text = DateTime.Today.Date.ToShortDateString(); this. toolStripStatusLabelTime.Text = DateTime.Now.ToLongTimeString();
40
Run your program Youll see the current date and time Notice: the time is static; it does not change its value.
Note:
Date and time may not be the same as with the above shown picture.
41
//Local Date and Time this. toolStripStatusLabelDate.Text = DateTime.Today.Date.ToShortDateStrin g(); this. toolStripStatusLabelTime.Text = DateTime.Now.ToLongTimeString();
Part III: Display the Icon and Name of the Selected Form
43
Go back to the Code window of the mdiMain Select the Events icon from the Properties Window Double-click MdiChildActivate
44
bool formtry = false; try { this.toolStripStatusLabel2.Text = this.ActiveMdiChild.Text; this.toolStripStatusLabel2.Image = this.ActiveMdiChild.Icon.ToBitmap(); } catch //(Exception msg) //without exception { //MessageBox.Show(msg.Message); formtry = true; } finally { if (formtry == true) { this.toolStripStatusLabel2.Text = null; this.toolStripStatusLabel2.Image = null; } }
45
46
47
Add a ToolStrip
48
Go back to the Items property Click the ellipsis to see the Items Collection Editor Click Add, change the Name to toolStripButtonCustomer Change the Image property (select icon which is similar to Customer form #39) Delete the Text value Type Customer in the ToolTipText property
49
Click Add again, change the Name to toolStripButtonProduct Delete the Text value Type Product in the ToolTipText property Change the Image property (select icon which is similar to Product form #32)
50
Click Add again, change the Name to toolStripButtonSupplier Delete the Text value Type Supplier in the ToolTipText property Change the Image property (select icon which is similar to Supplier form #27)
001 Introduction to MDI in C#.Net 51
52
Note: Upon click of the tool strip button it will call the Customer Menu
53
supplierToolStripMenuItem_Click(this, System.EventArgs.Empty);
54
Press F5 Hover your mouse pointer on top of each button Click each button As you click each button it calls the corresponding menu item for displaying the form With this, we do not need to re-type our codes We simply call the appropriate menu
001 Introduction to MDI in C#.Net 55
56
Put your cursor just above public mdiMain() but inside the namespace Declare the following:
namespace SalesInv { public partial class mdiMain : Form { #region Private Variables private frmCustomer frmNewCust = new frmCustomer(); private frmProduct frmNewProd = new frmProduct(); private frmSupplier frmNewSupp = new frmSupplier(); #endregion
public mdiMain() {
001 Introduction to MDI in C#.Net 57
Delete all existing codes from Customer, Products, and Supplier menus Or you may just comment them out using /* and */
58
Go Back to mdiMain
59
if (!(frmNewCust==null)) { if (!(frmNewCust.IsDisposed)) { frmNewCust.MdiParent = this; frmNewCust.Show(); frmNewCust.Focus(); frmNewCust.WindowState = FormWindowState.Normal; frmNewCust.BringToFront(); } else { frmNewCust = new frmCustomer(); frmNewCust.MdiParent = this; frmNewCust.Show(); } } else { frmNewCust = new frmCustomer(); frmNewCust.MdiParent = this; frmNewCust.Show(); } 001 Introduction to MDI in C#.Net 60
if (!(frmNewProd == null)) { if (!(frmNewProd.IsDisposed)) { frmNewProd.MdiParent = this; frmNewProd.Show(); frmNewProd.Focus(); frmNewProd.WindowState = FormWindowState.Normal; frmNewProd.BringToFront(); } else { frmNewProd = new frmProduct(); frmNewProd.MdiParent = this; frmNewProd.Show(); } } else { frmNewProd = new frmProduct(); frmNewProd.MdiParent = this; frmNewProd.Show(); } 001 Introduction to MDI in C#.Net 61
toolStripStatusLabel2.Text = "Connecting..."; if (!(frmNewSupp == null)) { if (!(frmNewSupp.IsDisposed)) { frmNewSupp.MdiParent = this; frmNewSupp.Show(); frmNewSupp.Focus(); frmNewSupp.WindowState = FormWindowState.Normal; frmNewSupp.BringToFront(); } else { frmNewSupp = new frmSupplier(); frmNewSupp.MdiParent = this; frmNewSupp.Show(); } } else { frmNewSupp = new frmSupplier(); frmNewSupp.MdiParent = this; frmNewSupp.Show(); 001 Introduction to MDI in C#.Net }
62
63
64
65
Add NotifyIcon
Go back to your mdiMain From the ToolBox, double-click NotifyIcon Change its name to: notifyIconMain Select a new Icon, preferably similar to mdiMain (#32) Set the Text to: Sales and Inventory System Set Visible to: False Leave this control temporarily and go back to the mdiMain
001 Introduction to MDI in C#.Net 66
Add a ContextMenuStrip
Double-click the ContextMenuStrip from the ToolBox Change its name to: contextMenuStripMain Click the contextMenuStrip from the mdiMain then type: &Show showToolStripMenuItem
M&inimized minimizedToolStripMenuItem1
67
On Maximized, type:
On Minimized, type:
68
Go back to mdiMain Click NotifyIcon On the Properties Window, select the ContextMenuStrip property Then select ContextMenuStrip Note: It may take time to display ContextMenuStrip from the options.
69
Run your program Click Hide In the System Tray, right-click the NotifyIcon
70
71
Double-click Exit from the mnuMain Type if (MessageBox.Show("Are you sure?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { this.Close(); }
72
Summary
MDI and children forms Menu strip, tool strip, status strip, notify icon, context menu strip LayoutMDI cascade, horizontal, vertical Hide, show, minimized, maximized, normal Date and time codes
Activity
Develop a User Interface (UI) of a Sales and Inventory System with the following objects:
MDI Form Children Forms Menus, tool, status, and context menu strips Notify icons
The UI must contain the codes that will make the following fully functional:
File Maintenance
Windows
Cascade Horizontal Vertical Arrange
74
Criteria
Forms appear once on click of menus or toolbar icons, hot-keys, and shortcut keys (30%) Name, icon, date, and time appear on the status strip (20%) Layout changes on click of cascade, horizontal, vertical, and arrange (20%) Asks for confirmation on exit (5%) Hides the main form (5%) Responds to the selected context menu options (20%)
001 Introduction to MDI in C#.Net 75