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.

Slides:



Advertisements
Similar presentations
1 Using a DataGridView. 2 The DataGridView The DataGridView is a high level control that presents data in a form similar to an Excel spreadsheet. Can.
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
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.
 2006 Pearson Education, Inc. All rights reserved Introduction to the Visual C# 2005 Express Edition IDE.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
1 of 6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
MENUS AND THE MENU EDITOR Elements of a Menu Menu bar Menu title Separator bar Menu items.
Using the Visual Basic Editor Visual Basic for Applications 1.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Copyright © 2012 Pearson Education, Inc. Chapter 2 Introduction to Visual C#
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.
File Management and Organisation © Copyright William Rowan 2007.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Microsoft Visual Basic 2005 ENRICHMENT CHAPTER Visual Studio Tools for Office.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Dr Dat Tran - Week 4 Lecture Notes 1 MenuStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Menus,MonthCalender, DateTimePicker, MDI,Tree View, List View,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 2 Welcome Application Introducing the Visual Basic 2008 Express Edition IDE.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 6 Switchboards, PivotTables, and PivotCharts.
Debugging and Menus Part07dbg --- Solving the problem, Debugging in Break time, Menus.
Productivity Programs Common Features and Commands.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Copyright © 2010 Wolters Kluwer Health | Lippincott Williams & Wilkins Introduction to Windows Chapter 2.
1 Scroll Bars Providing Scrollbars. 2 Objectives You will be able to: Use Windows Graphics to display tabular information on a Windows form. Add graphics.
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.
BIL528 – Bilgisayar Programlama II Introduction 1.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
Microsoft Access 2010 Chapter 10 Administering a Database System.
Visual Basic.NET BASICS Lesson 1 A First Look at Microsoft Visual Basic.NET.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Visual Basic CDA College Limassol Campus Lecture:Pelekanou Olga Semester C Week - 1.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
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.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
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.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
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 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
2 At the top of the zone in which you want to add the Web Part, click Add a Web Part. In the Add Web Parts to [zone] dialog box, select the check box of.
2 At the top of the zone in which you want to add the Web Part, click Add a Web Part. In the Add Web Parts to [zone] dialog box, select the check box of.
Using Procedures and Exception Handling
How to Add Images Using an 'openFile' Dialog
Module 8: Creating Windows-based Applications
Presentation transcript:

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 commands. Use a standard Open File dialog to permit a user to select a file to be opened.

3 The Schedule Viewer Program Existing program in Downloads area. Downloads/2011_02_17_Schedule_Viewer/ Downloads/2011_02_17_Schedule_Viewer/ Reads a CSV file consisting of schedule entries and displays the schedule. File path is hard coded. Program opens the file on startup.

4 The Schedule Viewer Program We will add a menu. Traditional Windows menu. Includes an Open command. We will also add an Open File dialog Permit the user to select the file to be viewed. Traditional Windows Look and Feel

5 Download There is a zipped project folder and a data file in the Downloads area of the class web site: Downloads/2011_02_17_Schedule_Viewer/ Downloads/2011_02_17_Schedule_Viewer/ Schedule_Viewer.zip Also, download the CSV schedule files. Put the csv files into a convenient folder and set the path string in Form1.cs to match the Spring Build and run the project

6 Schedule Viewer

7 Tighten Up Some More Columns cols[3].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; cols[3].Width = 30; // Credit Hours cols[6].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; cols[6].Width = 30; // Seats Open

8 Program Running

9 Menu Conventions Windows programs often have a menu bar. Follow a pattern in their menus File New Open Save Print Exit Edit Copy Paste Users are familiar with this pattern.

10 How to Create a Menu Design Time Normal case Menu Editor in Visual Studio.NET Run Time Program can build menu dynamically

11 Creating a Menu at Design Time Open Form1 [Design] View Toolbox Expand “Menus & Toolbars” section Drag the MenuStrip to the form.

12 Add MenuStrip to Form

13 Add MenuStrip to Form Menu component appears here (in “component tray”)

14 The Component Tray Represents components that do not otherwise provide a visible surface at design time. Provides a way to access and set the properties of those components at design time. Right click on control in component tray and select “Properties” to view and set its properties.

Working with the MenuStrip Menu template appears here Type the menu heading here. (e.g., &File)

16 Working with the MenuStrip A menu strip template appears at the top of the design surface. If not, click on menuStrip1 in the component tray. May need to expand the grey strip just below the title bar. Type &File in the “Type Here” box Type &Open in the next box that appears under the first one.

Working with the MenuStrip

18 Why “&” The “&” in front of a letter in a menu caption defines a key to open that menu. At runtime, the F in the menu caption will be underlined as a cue to the user The user can type ALT+F to open the menu. Same effect as clicking on the caption. Holding down ALT, the user can type O to select the Open command. Same effect as clicking on the command.

19 Menu Events There are a lot of menu events See Events in Properties window. You can write code to handle any of these events. Normally you only need to be concerned with one of them: Click

20 How to Provide a “Click” Function In designer mode, click on the menu caption. (e.g., File) The menu drops down. Double click on the menu item. Visual Studio creates a stub for the Click function for that item and takes you to that point in the code window.

Menu Events Double click here.

22 How to Provide a “Click” Function This appears in the editor window: private void openToolStripMenuItem_Click(object sender, EventArgs e) { } Add your code to handle the “Open” command here. You normally won’t need to use these arguments.

23 Add Open Event Handler Fill in a dummy event handler for now: MessageBox.Show("Open command");

24 Build and start Menu should appear. Open should display message box.

25 Add Code to Handle Open Command Modify the program to open c:\schedule_2011_fall.csv and display the schedule when the user clicks Open Move the call to import_schedule() and following statements from Form1_Load to openToolStripMenuItem_Click replacing MessageBox.Show() Try it!

26 Initial Form

27 After Open command

28 Adding Commands to the Menu Continue for as many commands as you need for that menu Example: &Open &Save To create a separator bar, type a minus sign as the command name.

29 Adding Commands to the Menu Continue to add command names and separator bars as needed. Example: &Open &Save - &Print - E&xit Note that these are the conventional access keys for commands by these names.

30 Setting Menu Item Properties Right click on the menu component in the component tray Select “Properties” on the pop up menu.

31 Setting MenuStrip Properties You can change properties of the overall MenuStrip in its Properties window. Example: RightToLeft supports languages that write from right to left. You won’t need to think about this so long as you only use English in your application. FYI – Microsoft provides extensive support for “internationalization”.

32 Setting Menu Item Properties Each item on the menu has its own properties. Right click on the item to open a context menu, then click on Properties.

33 Setting Properies of Open Right click here. Then click here. Properties window for the menu item appears.

34 Shortcut Keys Shortcut Keys vs. Access Keys Access Keys, like Alt+X, only work when the menu is dropped down. When you could click the command A “shortcut” key can be used at any time Example: Ctrl+S for Save You can use the Properties window to define shortcut keys. Ctrl+O for Open

Click here to get Dropdown List of available shortcut keys.

Scroll down (if necessary) and select name of desired shortcut key.

37 Shortcut Keys

38 Shortcut Keys At runtime the menu will indicate the shortcut key in the form Ctrl+O

39 How to Disable a Menu Item Sometimes a command doesn’t make sense. e.g. “Print” when there is nothing to print Rather than giving an error message, make the command unavailable. You could remove the item from the menu, or you could just disable it. Set the Enabled property to false.

40 Exit Command Let’s add an Exit command to the File menu. If you have not already done so, Type – in command name box to create a separator. Type E&xit for the Exit command.

Adding the Exit Command Double click on Exit command to add event handler.

42 Example: Exit Command private void exitToolStripMenuItem_Click( object sender, EventArgs e) { this.Close(); } Try it! End of Section

43 Common Dialog Controls Permit the user to say where to open or save a file by navigating to it. Let’s add an Open File dialog for our Open command. Replace hard coded file path.

44 Adding an OpenFileDialog View > Toolbox Expand Dialogs section Drag OpenFileDialog to form

Adding an OpenFileDialog

46 Adding an OpenFileDialog openFileDialog1 appears in the component tray.

47 Add to import_schedule void import_schedule() { StreamReader Reader = null; String input_line; String file_name; Schedule = new List (); file_name openFileDialog1.FileName = file_name; DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { file_name = openFileDialog1.FileName; }

Being More User-Friendly

49 New Open File Dialog

50 Summary Adding a menu bar to a Windows program is easy. Menu commands work essentially just like buttons. Common File Dialogs permit uses to select files in the customary manner.