SlideShare a Scribd company logo
1 of 13
Download to read offline
Visual C# .Net using
framework 4.5
Eng. Mahmoud Ouf
Lecture 08
mmouf@2017
Menu
In windows applications, menus are used to provide a list of commands
available for user to execute in the application. Example the File menu,
which contain New, Open, Close, …
The menu that sits between a form’s title bar and the client area is referred as
main menu.
Many application support Shortcut menus, context menus, which are menus
that appear at the mouse cursor position when you right click the mouse.
A main menu is associated with a form, while context menu is associated
with a particular control, that is clicking different controls often causes
different context menus to be invoked.
A menu (main or context) contains menu items, such as File, Open, Save,..
mmouf@2017
Menu
You will find that the File and Edit menu items are different from the Open,
Save items. File, Edit are located at the visible part of the program main
menu, while other are not.
The items at the visible part are called “Top Level Item”. Selecting any Top
Level Item will invoke a menu was called “PopUp menu” or “Drop Down
Menu” but now is called SubMenu or ChildMenu.
From the Windows Forms program, The File menu item contains a
collection of other menu items contains (Open, Save,…) and the Edit menu
item contains a collection of menu items contains (Cut, Copy,…).
One step back, the Main menu itself is a collection of menu items contains
(File, Edit,…). Each menu item in the Main menu is associated with its own
array of menu items. And in some case some of these menu items have their
own array of menu items.
mmouf@2017
Menu
Similarly, a context menu is an array of menu items.
To Deal With menus, we have 3 classes:
MenuStrip (the main menu)
ToolStripMenuItem (sub menus)
ContextMenuStrip (context menu)
mmouf@2017
Menu
Creating the Main Menu
1) Create an object from the MenuStrip class
2) Create the Top Level Menu item (object from ToolStripMenuItem
class)
3) Add this object (from ToolStripMenuItem) to the object (from
MenuStrip) use “items collection”
4) Now, make the submenu item (Object from ToolStripMenuItem)
5) Add it to the Top Level Menu (use DropDownItems collections)
6) Repeat steps 4, 5 to add other submenu
7) Repeat Steps 2 to 6 to add other top level Menu items
8) Attach MainMenu to the Form
mmouf@2017
Menu
Creating the Main Menu
Step 1:
MenuStrip menuStrip1; //define the object
menuStrip1 = new MenuStrip(); //object creation
Step 2:
ToolStripMenuItem fileToolStripMenuItem =
new ToolStripMenuItem(“&File”);
Step 3:
menuStrip1.Items.Add(this.fileToolStripMenuItem);
mmouf@2017
Menu
Creating the Main Menu
Step 4:
ToolStripMenuItem exitToolStripMenuItem =
new ToolStripMenuItem (“E&xit”,
new EventHandler(this.exitToolStripMenuItem_Click));
exitToolStripMenuItem.ShortcutKeys = (Keys)(Keys.Control | Keys.X);
Step 5:
fileToolStripMenuItem.DropDownItems.Add(this.exitToolStripMenuItem);
Step 8:
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
mmouf@2017
Menu
Creating the Main Menu
Step 4:
ToolStripMenuItem exitToolStripMenuItem =
new ToolStripMenuItem (“E&xit”,
new EventHandler(this.exitToolStripMenuItem_Click));
exitToolStripMenuItem.ShortcutKeys = (Keys)(Keys.Control | Keys.X);
Step 5:
fileToolStripMenuItem.DropDownItems.Add(this.exitToolStripMenuItem);
Step 8:
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
mmouf@2017
Menu
Creating the Main Menu
The & in the menu name string, tell which variable will be associated with
the Alt key to open the menu
Also, each command may have a shortcut to execute this command with no
need to open the menu
mmouf@2017
Context Menu
Creating the Context Menu
1) Create an object from the ContextMenuStrip class
2) Now, make the submenu item (object from ToolStripMenuItem)
3) Add it to the ContextMenuStrip (using Items collections)
4) Repeat steps 2, 3 to add other submenu
5) Attach ContextMenuStrip to the Form (through contextMenuStrip
property of the form)
mmouf@2017
Toolbar
Toolbars provides an alternate means to activate a given menu item. Most
applications use toolbar images that are 16 pixels square.
This is done by ToolStrip class
It can Contains:
ToolStripButton,
ToolStripLabel,
ToolStripDropDownButton,
ToolStripComboBox,
ToolStripTextBox
mmouf@2017
Toolbar
Creating and using Toolbar
1) Create object From ToolStrip class
2) Create objects From ToolStripButton, ToolStripLabel, … class
3) Configure each object
4) Configure toolbar and Add buttons (using Items collection)
5) Add the new bar to the control (using Controls collection)
mmouf@2017
Status bar
Status bars usually conveys textual information to the user.
This is done by StatusStrip class
It can Contains:
ToolStripStatusLabel,
ToolStripDropDownButton,
ToolStripProgressBar
Creating and using Status bar
1) Create object From StatusStrip class
2) Create objects From ToolStripStatusLabel,
ToolStripDropDownButton, … class
3) Configure each object
4) Configure status bar and Add buttons (using Items collection)
5) Add the new bar to the control (using Controls collection)
mmouf@2017

More Related Content

Viewers also liked

The Monster of Hate
The Monster of HateThe Monster of Hate
The Monster of HateOH TEIK BIN
 
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes libraryJunifar hidayat
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinFormHock Leng PUAH
 
¿Qué es red remedia?
¿Qué es red remedia?¿Qué es red remedia?
¿Qué es red remedia?REMEDIAnetwork
 
Pdfc fast food-mastercode.vn
Pdfc fast food-mastercode.vnPdfc fast food-mastercode.vn
Pdfc fast food-mastercode.vnMasterCode.vn
 
Publikasi Indikator Mutu Rumah Sakit Cakra Husada Klaten
Publikasi Indikator Mutu Rumah Sakit Cakra Husada KlatenPublikasi Indikator Mutu Rumah Sakit Cakra Husada Klaten
Publikasi Indikator Mutu Rumah Sakit Cakra Husada KlatenMade Sumiarta
 

Viewers also liked (13)

Intake 37 2
Intake 37 2Intake 37 2
Intake 37 2
 
The Monster of Hate
The Monster of HateThe Monster of Hate
The Monster of Hate
 
Intake 37 1
Intake 37 1Intake 37 1
Intake 37 1
 
Intake 37 linq3
Intake 37 linq3Intake 37 linq3
Intake 37 linq3
 
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
 
Intake 37 5
Intake 37 5Intake 37 5
Intake 37 5
 
Spf chapter 03 WinForm
Spf chapter 03 WinFormSpf chapter 03 WinForm
Spf chapter 03 WinForm
 
¿Qué es red remedia?
¿Qué es red remedia?¿Qué es red remedia?
¿Qué es red remedia?
 
Pdfc fast food-mastercode.vn
Pdfc fast food-mastercode.vnPdfc fast food-mastercode.vn
Pdfc fast food-mastercode.vn
 
Intake 37 ef1
Intake 37 ef1Intake 37 ef1
Intake 37 ef1
 
Publikasi Indikator Mutu Rumah Sakit Cakra Husada Klaten
Publikasi Indikator Mutu Rumah Sakit Cakra Husada KlatenPublikasi Indikator Mutu Rumah Sakit Cakra Husada Klaten
Publikasi Indikator Mutu Rumah Sakit Cakra Husada Klaten
 
Deutsche Angst
Deutsche AngstDeutsche Angst
Deutsche Angst
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 

Similar to Intake 37 8

1 PROBLEM You are to design and implement a Menu class.docx
1 PROBLEM You are to design and implement a Menu class.docx1 PROBLEM You are to design and implement a Menu class.docx
1 PROBLEM You are to design and implement a Menu class.docxhoney725342
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Ahsanul Karim
 
Windows xp stack
Windows xp stackWindows xp stack
Windows xp stackLisa Stack
 
VB6_OBJECTS AND GRAPHICS.ppt
VB6_OBJECTS AND GRAPHICS.pptVB6_OBJECTS AND GRAPHICS.ppt
VB6_OBJECTS AND GRAPHICS.pptBhuvanaR13
 
Components of windows.36
Components of windows.36Components of windows.36
Components of windows.36myrajendra
 
360 Flex Atlanta
360 Flex Atlanta360 Flex Atlanta
360 Flex Atlantartretola
 
Lecture windows xp 3
Lecture windows xp 3Lecture windows xp 3
Lecture windows xp 3Shafaq Saleem
 
How do i add a file menu to my java programSolutionHere goes .pdf
How do i add a file menu to my java programSolutionHere goes .pdfHow do i add a file menu to my java programSolutionHere goes .pdf
How do i add a file menu to my java programSolutionHere goes .pdffathimaoptical
 

Similar to Intake 37 8 (20)

Intake 38 8
Intake 38 8Intake 38 8
Intake 38 8
 
android menus
android menusandroid menus
android menus
 
Android ui menu
Android ui menuAndroid ui menu
Android ui menu
 
Vs c# lecture5
Vs c# lecture5Vs c# lecture5
Vs c# lecture5
 
Android session 3
Android session 3Android session 3
Android session 3
 
1 PROBLEM You are to design and implement a Menu class.docx
1 PROBLEM You are to design and implement a Menu class.docx1 PROBLEM You are to design and implement a Menu class.docx
1 PROBLEM You are to design and implement a Menu class.docx
 
Gui
GuiGui
Gui
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
 
01 10 - graphical user interface - others
01  10 - graphical user interface - others01  10 - graphical user interface - others
01 10 - graphical user interface - others
 
Swing jecrc
Swing jecrc Swing jecrc
Swing jecrc
 
Windows xp stack
Windows xp stackWindows xp stack
Windows xp stack
 
Windows xp
Windows xpWindows xp
Windows xp
 
VB6_OBJECTS AND GRAPHICS.ppt
VB6_OBJECTS AND GRAPHICS.pptVB6_OBJECTS AND GRAPHICS.ppt
VB6_OBJECTS AND GRAPHICS.ppt
 
Components of windows.36
Components of windows.36Components of windows.36
Components of windows.36
 
360 Flex Atlanta
360 Flex Atlanta360 Flex Atlanta
360 Flex Atlanta
 
Vp lecture 11 ararat
Vp lecture 11 araratVp lecture 11 ararat
Vp lecture 11 ararat
 
Lecture windows xp 3
Lecture windows xp 3Lecture windows xp 3
Lecture windows xp 3
 
How do i add a file menu to my java programSolutionHere goes .pdf
How do i add a file menu to my java programSolutionHere goes .pdfHow do i add a file menu to my java programSolutionHere goes .pdf
How do i add a file menu to my java programSolutionHere goes .pdf
 
Menu stripe
Menu stripeMenu stripe
Menu stripe
 

More from Mahmoud Ouf

More from Mahmoud Ouf (20)

Relation between classes in arabic
Relation between classes in arabicRelation between classes in arabic
Relation between classes in arabic
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Intake 38 data access 4
Intake 38 data access 4Intake 38 data access 4
Intake 38 data access 4
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
Intake 38 data access 1
Intake 38 data access 1Intake 38 data access 1
Intake 38 data access 1
 
Intake 38 12
Intake 38 12Intake 38 12
Intake 38 12
 
Intake 38 11
Intake 38 11Intake 38 11
Intake 38 11
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Intake 38 7
Intake 38 7Intake 38 7
Intake 38 7
 
Intake 38 6
Intake 38 6Intake 38 6
Intake 38 6
 
Intake 38 5 1
Intake 38 5 1Intake 38 5 1
Intake 38 5 1
 
Intake 38 5
Intake 38 5Intake 38 5
Intake 38 5
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
Intake 38 3
Intake 38 3Intake 38 3
Intake 38 3
 
Intake 38 2
Intake 38 2Intake 38 2
Intake 38 2
 
Intake 38_1
Intake 38_1Intake 38_1
Intake 38_1
 
Intake 37 DM
Intake 37 DMIntake 37 DM
Intake 37 DM
 
Intake 37 linq1
Intake 37 linq1Intake 37 linq1
Intake 37 linq1
 
Intake 37 12
Intake 37 12Intake 37 12
Intake 37 12
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Intake 37 8

  • 1. Visual C# .Net using framework 4.5 Eng. Mahmoud Ouf Lecture 08 mmouf@2017
  • 2. Menu In windows applications, menus are used to provide a list of commands available for user to execute in the application. Example the File menu, which contain New, Open, Close, … The menu that sits between a form’s title bar and the client area is referred as main menu. Many application support Shortcut menus, context menus, which are menus that appear at the mouse cursor position when you right click the mouse. A main menu is associated with a form, while context menu is associated with a particular control, that is clicking different controls often causes different context menus to be invoked. A menu (main or context) contains menu items, such as File, Open, Save,.. mmouf@2017
  • 3. Menu You will find that the File and Edit menu items are different from the Open, Save items. File, Edit are located at the visible part of the program main menu, while other are not. The items at the visible part are called “Top Level Item”. Selecting any Top Level Item will invoke a menu was called “PopUp menu” or “Drop Down Menu” but now is called SubMenu or ChildMenu. From the Windows Forms program, The File menu item contains a collection of other menu items contains (Open, Save,…) and the Edit menu item contains a collection of menu items contains (Cut, Copy,…). One step back, the Main menu itself is a collection of menu items contains (File, Edit,…). Each menu item in the Main menu is associated with its own array of menu items. And in some case some of these menu items have their own array of menu items. mmouf@2017
  • 4. Menu Similarly, a context menu is an array of menu items. To Deal With menus, we have 3 classes: MenuStrip (the main menu) ToolStripMenuItem (sub menus) ContextMenuStrip (context menu) mmouf@2017
  • 5. Menu Creating the Main Menu 1) Create an object from the MenuStrip class 2) Create the Top Level Menu item (object from ToolStripMenuItem class) 3) Add this object (from ToolStripMenuItem) to the object (from MenuStrip) use “items collection” 4) Now, make the submenu item (Object from ToolStripMenuItem) 5) Add it to the Top Level Menu (use DropDownItems collections) 6) Repeat steps 4, 5 to add other submenu 7) Repeat Steps 2 to 6 to add other top level Menu items 8) Attach MainMenu to the Form mmouf@2017
  • 6. Menu Creating the Main Menu Step 1: MenuStrip menuStrip1; //define the object menuStrip1 = new MenuStrip(); //object creation Step 2: ToolStripMenuItem fileToolStripMenuItem = new ToolStripMenuItem(“&File”); Step 3: menuStrip1.Items.Add(this.fileToolStripMenuItem); mmouf@2017
  • 7. Menu Creating the Main Menu Step 4: ToolStripMenuItem exitToolStripMenuItem = new ToolStripMenuItem (“E&xit”, new EventHandler(this.exitToolStripMenuItem_Click)); exitToolStripMenuItem.ShortcutKeys = (Keys)(Keys.Control | Keys.X); Step 5: fileToolStripMenuItem.DropDownItems.Add(this.exitToolStripMenuItem); Step 8: this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; mmouf@2017
  • 8. Menu Creating the Main Menu Step 4: ToolStripMenuItem exitToolStripMenuItem = new ToolStripMenuItem (“E&xit”, new EventHandler(this.exitToolStripMenuItem_Click)); exitToolStripMenuItem.ShortcutKeys = (Keys)(Keys.Control | Keys.X); Step 5: fileToolStripMenuItem.DropDownItems.Add(this.exitToolStripMenuItem); Step 8: this.Controls.Add(this.menuStrip1); this.MainMenuStrip = this.menuStrip1; mmouf@2017
  • 9. Menu Creating the Main Menu The & in the menu name string, tell which variable will be associated with the Alt key to open the menu Also, each command may have a shortcut to execute this command with no need to open the menu mmouf@2017
  • 10. Context Menu Creating the Context Menu 1) Create an object from the ContextMenuStrip class 2) Now, make the submenu item (object from ToolStripMenuItem) 3) Add it to the ContextMenuStrip (using Items collections) 4) Repeat steps 2, 3 to add other submenu 5) Attach ContextMenuStrip to the Form (through contextMenuStrip property of the form) mmouf@2017
  • 11. Toolbar Toolbars provides an alternate means to activate a given menu item. Most applications use toolbar images that are 16 pixels square. This is done by ToolStrip class It can Contains: ToolStripButton, ToolStripLabel, ToolStripDropDownButton, ToolStripComboBox, ToolStripTextBox mmouf@2017
  • 12. Toolbar Creating and using Toolbar 1) Create object From ToolStrip class 2) Create objects From ToolStripButton, ToolStripLabel, … class 3) Configure each object 4) Configure toolbar and Add buttons (using Items collection) 5) Add the new bar to the control (using Controls collection) mmouf@2017
  • 13. Status bar Status bars usually conveys textual information to the user. This is done by StatusStrip class It can Contains: ToolStripStatusLabel, ToolStripDropDownButton, ToolStripProgressBar Creating and using Status bar 1) Create object From StatusStrip class 2) Create objects From ToolStripStatusLabel, ToolStripDropDownButton, … class 3) Configure each object 4) Configure status bar and Add buttons (using Items collection) 5) Add the new bar to the control (using Controls collection) mmouf@2017