Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.

Slides:



Advertisements
Similar presentations
Multiple Forms, Standard Modules, And Menus
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Programming In Visual Basic .NET
110-H1 More VB Tools Creating a Menu: What is a menu? a group of (related) commands displayed at at the top of an application Top level menu Disabled command.
Dialog Boxes and Menus. Menus Menu Bar Contains menus which drop down to display list of menu items Each item has a name and text property Each item has.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
C# Programming: From Problem Analysis to Program Design1 9 Programming Based on Events.
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 7 Multiple Forms, Modules,
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Chapter 5 - Menus, Sub Procedures, and Sub Functions  Menus - controls - properties and events –menu editor - create and change –defining menus - menu.
Programming Based on Events
A Guide to Oracle9i1 Creating an Integrated Database Application Chapter 8.
MENUS AND THE MENU EDITOR Elements of a Menu Menu bar Menu title Separator bar Menu items.
Creating Menu. Objectives Create a menu system for a form –Create a menu –Create a menu titles –Create a menu items –Create a submenu –Modify menu –Edit.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 1 Introduction to Programming and C# Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Visual Basic Chapter 1 Mr. Wangler.
CIS162AD - C# Methods, Menus, and Dialog Boxes 05_methods_menus.ppt.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Multiple Forms, Standard Modules, And Menus
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 2 More Controls Programming in C#. NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Debugging and Menus Part07dbg --- Solving the problem, Debugging in Break time, Menus, Common Dialogs, and User-written methods.
Debugging and Menus Part07dbg --- Solving the problem, Debugging in Break time, Menus.
VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Chapter 6 OOP: Creating Object-Oriented Programs Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 2 Manipulating.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Revising Presentation Text Lesson 3.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls.
Object-Oriented Application Development Using VB.NET 1 Chapter 10 VB.NET GUI Components Overview.
Menus Menus provide groups of related commands for windows applications Menu, menu items, submenus A menu item that contains a submenu is considered to.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
6-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Chapter 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
Chapter 2 More Controls Programming in C#. NET Objectives Use text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Chapter 7, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 7 Multiple Forms, Standard Modules, And Menus.
Chapter 1: An Introduction to Visual Basic 2015
Using Procedures and Exception Handling
Brief description on how to navigate within this presentation (ppt)
Presentation transcript:

Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.

5- 2 Objectives Create menus and submenus for program control Display and use the Windows common dialog boxes Write reusable code in methods and call the methods from other locations

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Menus Consist of a menu bar containing menus with list of menu items Use menu items in place of or in addition to buttons to activate a method Menu items are controls with properties and events Create menus with the Visual Studio Menu Designer

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Defining Menus Add a MainMenu control to a form from the toolbox The MainMenu control appears in the component tray Enter text at words Type Here

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved The Text and Name Properties The Text property holds the words that appear on the screen Use the ampersand (&) to specify the key for keyboard access in the Text property The Name property gives the MenuItem a name To assign a Name, append suffix “Menu” for top- level menu names and “MenuItem” for items on the menu

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Submenus A new list that pops up under an item on a menu is called a submenu A filled triangle to the right of a menu item indicates a submenu for that menu item Create a submenu by moving to the right of a menu item and typing the next item’s text

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Separator Bars A separator bar in a menu groups menu items according to their purpose Two ways to create a separator bar –Type a single hyphen (-) for the text –Right-click on Menu Designer at separator bar position and choose Insert Separator Keep the default Name property of the separator bar control

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating a Menu – Step-by-Step You are going to create a project with one form and a menu bar that contains these menu items: FileHelp Exit About 1.Create the Menu Items 2.Change the Properties of the Menu Items 3.Write the Code Double-click on a menu item to open the Editor window in the control’s Click event-handling method

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Modifying Menu Items Use the Menu Designer to modify menu items –Right-click on the menu bar for options including Delete, Insert New, Insert Separator, and Edit Names –Drag and drop menu items to rearrange

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved The Enabled Property The Enabled property is true by default An enabled menu item has black text and is available for selection A disabled menu item is grayed out and not available Set the Enabled property at design time or in code at run time

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved The Checked Property A menu item may contain a check mark next to it to indicate the option is currently selected By default, the Checked property is set to false Change the Checked property at design time or in code at run time

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Setting Keyboard Shortcuts Create keyboard shortcuts for your menu items –Select the menu item in the designer –Select the Shortcut property in the Properties window –Select choice from drop down list ShowShortcut property is true by default

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Standards for Windows Menus Include keyboard access keys and stick with the standard key assignments Place the File menu on the left end of the menu bar with an Exit command at the end If there is a Help menu, it should be at the right end of the menu bar Any menu item that will display a dialog box should have “…” appended to its Text property

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Common Dialog Boxes Common dialog controls are used to display dialog boxes that are provided with Windows Visual Studio.NET supports the following common dialog controls - OpenFileDialog- SaveFileDialog - FontDialog- ColorDialog - PrintDialog- PrintPreviewDialog

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Displaying a Common Dialog Box Use the ShowDialog method Example: ColorDialog1.ShowDialog(); A modal dialog box stays on top of the application and must be responded to –Use the ShowDialog method A modeless dialog box does not require a response –Use the Show method

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Using the Information from the Dialog Box Color Dialog Box –The color selected by user stored in the Color property –Assign this property to another object Font Dialog Box –The font selected by user stored in the Font property –Assign this property to another object Initialize the Font or Color property to an existing value –Example: FontDialog1.Font = subTotalLabel.Font;

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating Context Menus Context menus are the shortcut menus that pop up when you right-click on an object Items on a context menu are generally specific to that object Add a ContextMenu control to the form Click on words Context Menu then Type Here to add menu items

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating Context Menus cont. An application can have more than one context menu Assign the context menu to a form or control with the ContextMenu property If there is only one context menu, attach it to the form

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating a Context Menu – Step-by-Step You are going to create a context menu that contains these menu items: Color… Font… Exit… 1.Add the Context Menu to a Form 2.Test the Program

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Writing General Methods A general method contains reusable code that is called from other methods The method may return a value or not –If a value is returned, specify the return type before the method name –If no value is returned, use the keyword void before the method name

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating a New Method Write a method header and enclose the lines of code within a set of braces Example: private void SelectColor() { //Display the color dialog box ColorDialog1.ShowDialog(); }

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Creating a New Method cont. You must specifically call the method from another method Example: private void changeButtonMessage_Click(object sender, System.EventArgs e) { //Change the color of the message SelectColor(); messageLabel.ForeColor = ColorDialog1.Color; }

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Passing Arguments to Methods Use arguments when you need to use the value of a variable in one method and also in a second method that is called from the first Any arguments defined in a method must be supplied in a call to that method The argument value must be the same data type in both locations The name of an argument does not have to be the same in both locations

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Writing Methods That Return Values Write a method that will calculate a value and return it to the place where the method was called The type of data returned is defined in the method header A method can return a value and use one or more arguments The name given an argument in the header is the name used to refer to that argument inside the method

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Returning the Result of a Method The return value is passed back with a Return statement The keyword Return is followed by a variable or expression containing the value to return to the caller If the method header specifies void, no Return statement is required

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Method Header Format Method nameArgument data type Return data typeArgument Access modifier private decimal Commission(decimal decSalesAmount)

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Methods with Multiple Arguments The sequence and data type of the arguments in the call must exactly match the arguments in the method header The list of zero or more arguments is enclosed in parentheses When you call the method, the Visual Studio.NET smart editor displays the arguments of your method

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Breaking Calculations into Smaller Units Projects with many calculations can be easier to understand and write if broken down into small units Each unit should perform one program function or block of logic

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Your Hands-On Programming Example Modify the hands-on programming example from Chapter 4 by replacing some of the buttons with menus. Write a method to calculate the sales tax and allow the user to select the font and color of the summary labels.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary The Visual Studio Menu Designer enables you to create menus, menu items, and submenus, each with keyboard access keys. In the Menu Designer you can set and modify the order and level of menu items. Each menu item has a Click event. The code to handle selection of a menu item belongs in the item’s Click event-handling method.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary cont. Common dialog boxes allow C# programs to display the predefined Windows dialog boxes for Print, PrintPreview, File Open, File Save, Fonts, and Colors. Context menus, or shortcut menus, are created using a ContextMenu control and the Menu Designer. Context menus pop up when the user right-clicks.

© 2003 by The McGraw-Hill Companies, Inc. All rights reserved Summary cont. The programmer can write reusable code in general methods. These methods can be called from any other method in the form class. Methods that return a value must specify the data type of the return value and set the value to return using a return statement. If the return type is void, no value can be returned.