St. Ambrose CSCI 480 - Menus, Common Dialog Boxes, and Methods

Unformatted text preview:

Chapter 5 Menus, Common Dialog Boxes, and MethodsMenusSlide 3SubmenusSubMenusSeparator BarsModifying Menu ItemsThe Enabled PropertyThe Checked PropertyChecked/Enabled PropertiesSetting Keyboard ShortcutsStandards for Windows MenusCommon Dialog BoxesDisplaying a Common Dialog BoxUsing the Information from the Dialog BoxCreating Context MenusContext MenusCreating Context Menus cont.Writing General MethodsCreating a New MethodCreating a New Method cont.Passing Arguments to MethodsMethod ParametersMethod Header FormatMethods with Multiple ArgumentsBreaking Calculations into Smaller UnitsPowerPoint PresentationChapter 5 Menus, Common Dialog Boxes, and MethodsProgramming in C# .NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.2Menus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Each Menu item is a control with properties and eventsCreate menus with the Visual Studio Menu Designer3Menus4Submenus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 text5SubMenus6Separator 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 orRight-click on Menu Designer at separator bar position and choose Insert SeparatorKeep the default Name property of the separator bar control7Modifying Menu ItemsUse the Menu Designer to modify menu itemsRight-click on the menu bar for options including Delete, Insert New (above), Insert Separator, Edit NamesDrag and drop menu items to rearrange8The 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 time9The 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 time10Checked/Enabled Properties11Setting 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Only work for lowest level item – ie. Items with submenusShowShortcut property is true by default12Standards 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 property13Common 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 - PrintPreviewDialog14Displaying a Common Dialog BoxUse the ShowDialog methodExample:dlgColor.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 method15Using the Information from the Dialog BoxColor Dialog BoxThe color selected by user stored in the Color propertyFont Dialog BoxThe font selected by user stored in the Font propertyInitialize the Font or Color property to an existing valueExample: FontDialog1.Font = subTotalLabel.Font;16Creating 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 items17Context Menus18Creating 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 form19Writing 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 name20Creating 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 boxColorDialog1.ShowDialog();}21Creating 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 messageSelectColor();messageLabel.ForeColor = ColorDialog1.Color;}22Passing 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 locations23Method Parameters24Method Header FormatMethod name Argument data typeReturn data type ArgumentAccess modifierprivate decimal Commission(decimal decSalesAmount)25Methods 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 method26Breaking 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


View Full Document

St. Ambrose CSCI 480 - Menus, Common Dialog Boxes, and Methods

Download Menus, Common Dialog Boxes, and Methods
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Menus, Common Dialog Boxes, and Methods and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Menus, Common Dialog Boxes, and Methods 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?