Keeping Track, Menus. CSC 330 Object-Oriented Programming 1

Similar documents
CIS 3260 Intro to Programming with C#

Menus, Common Dialog Controls, Context Menus, Sub Procedures, and Functions

Programming. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

Lesson 09 Working with. SDI and MDI. MIT Rapid Application Development By. S. Sabraz Nawaz Lecturer in MIT

Module 8: Building a Windows Forms User Interface

Copyright 2014 Pearson Education, Inc. Chapter 7. Multiple Forms, Modules, and Menus. Copyright 2014 Pearson Education, Inc.

Location of menu elements

Chapter 12: Using Controls

MenuStrip Control. The MenuStrip control represents the container for the menu structure.

Chapter 12: Using Controls

Philadelphia University Faculty of Information Technology. Visual Programming

You will have mastered the material in this chapter when you can:

Included with the system is a high quality speech synthesizer, which is installed automatically during the SymWord setup procedure.

Dive Into Visual C# 2010 Express

Using Visual Basic Studio 2008

Introductionto the Visual Basic Express 2008 IDE

Program and Graphical User Interface Design

Windows Programming Using C#

Menus and Printing. Menus. A focal point of most Windows applications

CIS 3260 Intro to Programming in C#

Lesson 4 - Creating a Text Document Using WordPad

Chapter 6. Multiform Projects The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

CST242 Windows Forms with C# Page 1

Menus. You ll find MenuStrip listed in the Toolbox. Drag one to your form. Where it says Type Here, type Weather. Then you ll see this:

1 Ctrl + X Cut the selected item. 2 Ctrl + C (or Ctrl + Insert) Copy the selected item. 3 Ctrl + V (or Shift + Insert) Paste the selected item

MS Word Basic Word 2007 Concepts

Windows 10 Essentials

CIS 3260 Intro. to Programming with C#

GIMP TEXT EFFECTS. Text Effects: Outline Completed Project

Introduction to the Visual Studio.NET Integrated Development Environment IDE. CSC 211 Intermediate Programming

Windows 7. More Skills 11 Manage Fonts. To complete this project, you will need the following file: You will save your file as: CHAPTER 7

LESSON A. The Splash Screen Application

Computer Science 110. NOTES: module 8

Chapter 2. Creating Applications with Visual Basic Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of

Bold, Italic and Underline formatting.

Word Tips & Tricks. Status Bar. Add item to Status Bar To add an itme to the status bar, click on the item and a checkmark will display.

Ingegneria del Software T. Interfaccia utente

REVIEW OF CHAPTER 1 1

Microsoft Excel Keyboard Shortcuts

How to Edit Your Website

Step 1: Start a GUI Project. Start->New Project->Visual C# ->Windows Forms Application. Name: Wack-A-Gopher. Step 2: Add Content

PART 7. Getting Started with Excel

SMART Recorder. Record. Pause. Stop

Working with PDF s. To open a recent file on the Start screen, double click on the file name.

How to Edit Your Website

COPYRIGHTED MATERIAL. Visual Basic: The Language. Part 1

Creating and Triggering Animations

LESSON B. The Toolbox Window

Chapter 3. Fundamentals of Programming in Visual Basic

Tutorials. Lesson 3 Work with Text

AutoCAD 2009 User InterfaceChapter1:

Microsoft Excel > Shortcut Keys > Shortcuts

SPARK. User Manual Ver ITLAQ Technologies

Copyright 2018 MakeUseOf. All Rights Reserved.

Outlook Web App. Getting Started. QUICK Source. Microsoft. in Exchange Server 2010

Recommended GUI Design Standards

GUI Design and Event- Driven Programming

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

ST NICHOLAS COLLEGE RABAT MIDDLE SCHOOL HALF YEARLY EXAMINATIONS February 2016

Dive Into Visual C# 2008 Express

Objectives. Objectives. Plan Ahead. Starting Excel 3/9/2010. Excel Chapter 3. Microsoft Office 2007

Excel 2003 Tutorial II

Optional Lab: Customize Settings in Windows Vista

Introduction. Create a New Project. Create the Main Form. Assignment 1 Lights Out! in C# GUI Programming 10 points

User s Manual Software Version 4.0

Start menu. Toggles between All Programs & Back

ITEC102 INFORMATION TECHNOLOGIES

Pelnor Help Add-in.

Chapter 6 Dialogs. Creating a Dialog Style Form

Microsoft Visual Basic 2005 CHAPTER 6. Loop Structures

CST272 Getting Started Page 1

Outlook: Web Access. Outlook: Web Access AIS Vienna

Guide to WB Annotations

STAR OFFICE WRITER. Lesson 2

Impress Guide Chapter 11 Setting Up and Customizing Impress

Microsoft Office Word. Part1

Unit 3--Alignment, Formatting Font--Size, Color, Style [Bold, Italic, and Underline] Block

Tutorials. Lesson 1 - Format a Schedule. In this lesson you will learn how to: Change the schedule s date range. Change the date headings.

2. In the Start and End Dates section, use the Calendar icon to change the Displayed Start Date to 1/1/2015 and the Displayed End Date to 5/31/2015.

Note: In this guide, wherever you see an underlined letter as part of a command word (ex. File), that refers to the keyboard shortcut

Chapter 2 Visual Basic, Controls, and Events. 2.1 An Introduction to Visual Basic 2.2 Visual Basic Controls 2.3 Visual Basic Events

PowerPoint 2016 Building a Presentation

Intro to Excel. To start a new workbook, click on the Blank workbook icon in the middle of the screen.

Format your assignment

7 For Seniors For Dummies

Section 3 Formatting

Programming in C# Project 1:

Quick Tips & Tricks. Important You must use SEMICOLONS ( ie; ) to separate address when sending mail to multiple users

Table of Contents Lesson 1: Introduction to the New Interface... 2 Lesson 2: Prepare to Work with Office

Computer Basics Written by Brian O'Rooney. Copyright 2000 Nanaimo Literacy Association All rights reserved

NiceForm User Guide. English Edition. Rev Euro Plus d.o.o. & Niceware International LLC All rights reserved.

AgWare ClickFORMS 7.0 Introductory Tutorial

AGB 260: Agribusiness Data Literacy. Excel Basics

page 1 OU Campus User Guide

Lesson 2 Quick Tour and Features

Contents. Launching Word

Office365 at Triton College

for G.C.E. Ordinary Level Examination

Quick Start Guide. ARIS Architect. Version 9.8 Service Release 2

PowerPoint 2010 Introduction. 4/18/2011 Archdiocese of Chicago Mike Riley

Transcription:

Keeping Track, Menus CSC 330 Object-Oriented Programming 1

Chapter Objectives Keeping Track Create menus and submenus for program control Display and use the Windows common dialog boxes Create context menus for controls and the form Write reusable code in methods and call the methods from other locations CSC 330 Object-Oriented Programming. 2

Keeping Track Various controls help us keep track of dates, time, and numbers DateTimePicker NumericUpDown StatusBar Timer CSC 330 Object-Oriented Programming. 3

Example KeepTrack CSC 330 Object-Oriented Programming. 4

Example KeepTrack operation DateTimePicker at top of form User chooses a date NumericUpDown in the middle User selects a number Button at bottom User presses to display date in a label and number selected in another label StatusBar a at bottom shows s current time Timer updates it every second, and changes label colors CSC 330 Object-Oriented Programming. 5

DateTimePicker Format Long Tuesday, January 28, 2003 Short 1/28/03 Time 10:32:56 AM CSC 330 Object-Oriented Programming. 6

Button Click handling private void showbutton_click { } (object sender, System.EventArgs e) datedisplay.text = "Date selected: " + date.value.tolongdatestring(); numberdisplay.text = "Number selected " + number.value.tostring(); CSC 330 Object-Oriented Programming. 7

A Timer control CSC 330 Object-Oriented Programming. 8

Timer Tick event every second private void timer1_tick (object sender, System.EventArgs e) { currentdatetime.text t T t = DateTime.Now.ToString(); T i number.backcolor = datedisplay.backcolor; datedisplay.backcolor = numberdisplay.backcolor; numberdisplay.backcolor = number.backcolor; } Copies time to status bar Permutes background colors to give flashing effect CSC 330 Object-Oriented Programming. 9

DateTimePicker properties and an event CSC 330 Object-Oriented Programming. 10

MonthCalendar control CSC 330 Object-Oriented Programming. 11

Menus Menu Bar Menus that drop down to display a list of menu items Menu items are controls with properties and events Each menu item has a Name and Text property and a Click event (similar to a button) Easy to create menus for a Windows form using Visual Studio's Menu Designer Menus look and behave like standard Windows menus CSC 330 Object-Oriented Programming. 12

Defining Menus - 1 Add a MenuStrip component to the form MenuStrip is a container which can contain ToolStripMenuItems ToolStripComboBoxes ToolStripSeparators S ToolStripTextBoxes CSC 330 Object-Oriented Programming. 13

Defining Menus - 2 The MenuStrip component appears in the component Tray Begin typing on top of the words "Type Here" Enter text for first menu Enter items for first menu or enter text for second menu A ToolStripMenuItem is automatically added to the MenuStrip's Items collection CSC 330 Object-Oriented Programming. 14

Holds the words that appear on the screen Similar to the Text property of a button or label Conform to Windows standards The first menu's Text property should be File, with a keyboard access key (&File) Enter or change the Text property for each menu and menu item Use the Menu Designer or the Properties window The Text Property CSC 330 Object-Oriented Programming. 15

Adding ToolStripMenuItems to a MenuStrip. Setting a menu item's shortcut keys CSC 330 Object-Oriented Programming. 16

Creating an access shortcut To create an access shortcut (or keyboard shortcut), type an ampersand (&) before the character to be underlined. d For example, to create the File menu item with the letter F underlined, type &File. To display an ampersand, type &&. To add other shortcut keys (e.g., <Ctrl>-F9) for menu items, set the ShortcutKeys property of the appropriate ToolStripMenuItems. To do this, select the down arrow to the right of this property in the Properties window. In the window that appears, use the CheckBoxes and dropdown list to select the shortcut keys. When you are finished, click elsewhere on the screen. You can hide the shortcut keys by setting property p ShowShortcutKeys to false, and you can modify how the control keys are displayed in the menu item by modifying property ShortcutKeyDisplayString. CSC 330 Object-Oriented Programming. 17

The Name Property The File menu item that is added is automatically named filetoolstripmenuitem Menu items are named so well that there is no need to change the Name property of any menu component If the Text property is changed, the item is not automatically renamed Rename it in the Properties window CSC 330 Object-Oriented Programming. 18

Menu item options In addition to text, Visual Studio allows you to easily add TextBoxes and ComboBoxes (drop-down lists) as menu items. Clicking the down arrow allows you to select the type of item to addmenuitem (of type ToolStripMenuItem, the default), ComboBox (of type ToolStripComboBox) and TextBox (of type ToolStripTextBox). CSC 330 Object-Oriented Programming. 19

Menu Item Options CSC 330 Object-Oriented Programming. 20

The MenuStrip Items Collection Items are automatically added in the Menu Designer Use the Items Collection Editor to reorder, add, and delete menu items Select the MenuStrip and in the Items property in the Properties window, click the ellipsis button CSC 330 Object-Oriented Programming. 21

A Menu's DropDownItems Collection Each top-level menu has a DropDownItems collection that holds the menu items In the Items Collection Editor you can rearrange or delete menu items and set properties of the items DropDownItems collection for the File menu CSC 330 Object-Oriented Programming. 22

A filled triangle to the right of a menu item indicates that a submenu exists Create a submenu by moving to the right of a menu item and typing the next item's text Submenus CSC 330 Object-Oriented Programming. 23

Separator Bars Group menu items according to their purpose Draws a bar across the entire menu To create a separator bar, add a new menu item and click on its drop-down arrow Select Separator or type a single hyphen in the Menu Designer CSC 330 Object-Oriented Programming. 24

Menu items have Enabled property set to true by default Enabled menu items appear in black text and can be selected Disabled items are not available Enabled property can be set at design time or run time, in code The Enabled Property instructionstoolstripmenuitem.enabled = false; CSC 330 Object-Oriented Programming. 25

The Checked Property Menu items have Checked property set to false by default A check mark next to a menu item indicates the option is selected Checked property can be set at design time or in code summarytoolstripmenuitem.checked = true; CSC 330 Object-Oriented Programming. 26

Toggling Check Marks On and Off Set a menu item s initial Checked property p in the Properties window To change the menu item s state in code, set its Checked property to true or false if (summarytoolstripmenuitem.checked) { // Uncheck the summary menu item. summarytoolstripmenuitem.checked = false; } else { } //Check the summary menu item. summarytoolstripmenuitem.checked = true; CSC 330 Object-Oriented Programming. 27

Setting Keyboard Shortcuts Many users prefer to use keyboard shortcuts for selecting menu items To set keyboard shortcuts Select the menu item in the designer In the Properties window, select the ShortcutKeys property Make a choice from the drop-down list Set ShowShortcutKeys property to false to prevent a shortcut from showing on the menu CSC 330 Object-Oriented Programming. 28

Design Example CSC 330 Object-Oriented Programming. 29

Example: Design GUI with Menu To create this GUI, begin by dragging the MenuStrip from the ToolBox onto the Form. Then use Design mode to create the menu structure shown in the sample outputs. The File menu (filetoolstripmenuitem) has menu items About (abouttoolstripmenuitem) and Exit (exittoolstripmenuitem); the Format menu (formattoolstripmenuitem) has two submenus. The first submenu, Color (colortoolstripmenuitem), contains menu items Black (blacktoolstripmenuitem), Blue (bluetoolstripmenuitem), Red (redtoolstripmenuitem) and Green (greentoolstripmenuitem). The second submenu, Font (fonttoolstripmenuitem), contains menu items Times New Roman (timestoolstripmenuitem), Courier (couriertoolstripmenuitem), Comic Sans (comictoolstripmenuitem), a separator bar (dashtoolstripmenuitem), Bold (boldtoolstripmenuitem) and Italic (italictoolstripmenuitem). CSC 330 Object-Oriented Programming. 30

Example: Design GUI with Menu cont d The About menu item in the File menu displays a MessageBox when clicked. The Exit menu item closes the application through static method Exit of class Application. Class Application's static methods control program execution. Method Exit causes our application to terminate. We made the items in the Color submenu (Black, Blue, Red and Green) mutually exclusive the user can select only one at a time. To indicate that a menu item is selected, we will set each Color menu item's Checked property to true. This causes a check to appear to the left of a menu item. Each Color menu item has its own Click event handler. The method handler for color Black is blacktoolstripmenuitem_click. lst k Similarly, il l the event handlers for colors Blue, Red and Green are bluetoolstripmenuitem_click, redtoolstripmenuitem_click and greentoolstripmenuitem_click, respectively. Each Color menu item must be mutually exclusive, so each event handler calls method ClearColor before setting its corresponding Checked property p to TRue. Method ClearColor sets the Checked property p of each color MenuItem to false, effectively preventing more than one menu item from being selected at a time. In the designer, we initially set the Black menu item's Checked property to true, because at the start of the program, the text on the Form is black. CSC 330 Object-Oriented Programming. 31

Standards for Windows Menus Follow Windows standards for menus Include keyboard access keys Stick with standard keyboard shortcuts Place File menu at the left end of the menu bar Place Help menu, if included, at the right end Any menu item that will display a dialog box asking for further information should have "..." appended to the Text property CSC 330 Object-Oriented Programming. 32

Common Dialog Boxes Predefined standard dialog boxes Specifying colors and fonts Opening, saving and browsing for files Place the desired common dialog component from the Dialogs tab of the toolbox in the Component Tray Default names for the components are fine CSC 330 Object-Oriented Programming. 33

Displaying a Windows Common Dialog Box Display the dialog box at run time using the ShowDialog method The dialogobject is the name of the common dialog component Write code to show the dialog in the event handler for a menu item or button colordialog1.showdialog(); fontdialog1.showdialog(); g() CSC 330 Object-Oriented Programming. 34

Modal versus Modeless Windows A dialog box is said to be modal The box stays on top of the application and must be responded to Use the ShowDialog method to display a dialog box, which is a window displayed modally A window that does not require response is said to be modeless Use the Show method to display a modeless window CSC 330 Object-Oriented Programming. 35

Using the Color Dialog Box Color selected in the Color dialog box is stored in the Color property Color property can be assigned to another object, such as a control Display dialog box with ShowDialog method User responds to dialog box Use the Color property p colordialog1.showdialog(); titlelabel.forecolor = colordialog1.color; CSC 330 Object-Oriented Programming. 36

Using the Font Dialog Box The Font common dialog box displays available fonts for the system display After the user makes a selection, the Font property can be assigned to other objects on the form fontdialog1.showdialog(); titlelabel.font = fontdialog1.font; CSC 330 Object-Oriented Programming. 37

Setting Initial Values Before executing the ShowDialog method, assign the existing values of the object's properties When the dialog box appears, the current values will be selected If the user presses Cancel, property setting for the objects will remain unchanged colordialog1.color = titlelabel.forecolor; colordialog1.showdialog(); titlelabel.forecolor il lf l = colordialog1.color; l 1C l fontdialog1.font = titlelabel.font; fontdialog1.showdialog(); titlelabel.font il lf = fontdialog1.font; 1F CSC 330 Object-Oriented Programming. 38

How to Base a New Project on an Existing Project - 1 Make sure the project is not open (very important) Copy the folder to a new location using Windows Explorer Rename the new folder for the new project name, still using Windows Explorer Open the new project (the copy) in the Visual Studio IDE CSC 330 Object-Oriented Programming. 39

How to Base a New Project on an Existing Project 2 In the IDE's Solution Explorer, rename the solution and the project Right-click on the name and choose Rename Display the solution, Tools/Options/Projects and Solutions/General/Always show solution Rename the form(s), if desired Open the Project Designer (Project/ProjectName Properties) ) and change the Assembly name and Default namespace entries to match the new project name CSC 330 Object-Oriented Programming. 40