Multi-form applications and dialogs

Slides:



Advertisements
Similar presentations
Chapter 1: An Introduction to Visual Basic 2012
Advertisements

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.
© by Pearson Education, Inc. All Rights Reserved.
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.
Chapter 1: An Introduction to Visual Basic.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using Multiple Forms. Creating a New Form ProjectAdd Windows Form.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Multiple Forms and Standard Modules
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
IE 411/511: Visual Programming for Industrial Applications
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Intro to MFC. Open VS and create new project 1)Open MS Visual Studio 2008 Professional (It must be the Professional Edition, the Express Edition will.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
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.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
Lab1 – Part III CSE 581 Roger Crawfis. To Do We have the basic framework, but need to: 1.Add the ability to open and read an image. 2.Generate pseudo-random.
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.
Tutorial 11 Five windows included in the Visual Basic Startup Screen Main Form Toolbox Project Explorer (Project) Properties.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
6-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
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.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Programming with Microsoft Visual Basic 2012 Chapter 1: An Introduction to Visual Basic 2012.
1 Displaying Dialog Boxes Kashef Mughal. 2 Midterm Stats Here we go  Average was  Low was 116  High was 184  Mid Quarter Grade - check any.
Module 3: Creating Windows-based Applications. Overview Creating the Main Menu Creating and Using Common Dialog Boxes Creating and Using Custom Dialog.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Dive Into® Visual Basic 2010 Express
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Chapter 1: An Introduction to Visual Basic .NET
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 1: An Introduction to Visual Basic 2015
Introduction to Microsoft Access
3.01 Apply Controls Associated With Visual Studio Form
Deploying and Configuring SSIS Packages
3.01 Apply Controls Associated With Visual Studio Form
Using Multiple Forms.
Visual studio 2010 SENG 403, Tutorial 2 SENG Winter 2011.
Programming with Microsoft Visual Basic th Edition
Using Procedures and Exception Handling
Windows Desktop Applications
Controls, Events, and More
Sequential Input and Output using Text Files
Chapter 6 Multiform Projects
NORMA Lab. 7 Generating Reports More Display Options
Chapter 2 – Introduction to the Visual Studio .NET IDE
Creating a Windows Forms User Interface
1. Open Visual Studio 2008.
Copyright © 2006 Thomas P. Skinner
Multi-Form Applications Things You Need to Know
Tonga Institute of Higher Education
Object-Oriented Programming: Inheritance and Polymorphism
Module 8: Creating Windows-based Applications
Using Templates and Library Items
– A principal I/O mechanism in Windows
HIBBs is a program of the Global Health Informatics Partnership Learning the Basics of Microsoft Word 2019 and Microsoft office support TFN
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Multi-form applications and dialogs Secondary Forms Multiform Applications November 17, 2018

Multiform applications Nearly all desktop GUI applications use more than a single form to do their jobs Visual Studio has the editor with many fly-out panels, dialogs to open or create projects, classes, resources, and so forth, save them, close them, debug them, and so forth Word processors have open/save/save as dialogs, select font or color dialogs, about boxes, and so forth Even browsers may have multiple sites open in different tabs, pop-up security messages or ads, and so forth Many applications have splash screens and about boxes at a minimum Multiform Applications November 17, 2018

Common Dialogs Some dialogs are so commonly needed among applications, that .NET supplies prewritten classes for you to use in such cases Tasks such as Opening or Saving a File, Selecting a Font, Choosing a Color, Displaying a Message in a MessageBox, and so forth are good candidates for such dialogs Among the common dialogs provided by the .NET class library are OpenFileDialog, SaveFileDialog, ColorDialog, FontDialog, PrintDialog, MessageBox, and PageSetupDialog These may be used as they are or tailored to suit the needs of the developer Multiform Applications November 17, 2018

Example Create new instance of ColorDialog If user did not dismiss by canceling the operation Display dialog Get selected color Multiform Applications November 17, 2018

Select color and click OK Example Color Dialog Result Select color and click OK Multiform Applications November 17, 2018

OpenFileDialog Multiform Applications November 17, 2018

OpenFileDialog Example Create dialog instance Caption for the dialog Filter: limits which files show in the dialog If the user Canceled the dialog, simply return; otherwise process the selected file When dialog first opens, initial directory is folder where app’s .exe is found Filter contains sequences of “description|*.ext” where “description” is a phrase that will be shown describing what is being shown and “*.ext” specifies which file extensions are shown Multiform Applications November 17, 2018

OpenFileDialog Example Caption Initial Directory Dropdown filter ComboBox Expanded Only .txt files shown Filter Multiform Applications November 17, 2018

SaveFileDialog Multiform Applications November 17, 2018

SaveFileDialog Example Create instance Set initial directory, caption, and filters Display dialog, and, if not cancelled by user, process the selected file Multiform Applications November 17, 2018

SaveFileDialog Example Caption Initial Directory Only *.txt files shown Filter Multiform Applications November 17, 2018

FontDialog Multiform Applications November 17, 2018

FontDialog Demo Create instance Set minimum and maximum allowable font sizes Initial font set to current font If user selected a font and did not cancel, make the label use that font Multiform Applications November 17, 2018

FontDialog Example Click Button Multiform Applications November 17, 2018

Right click on project, choose Add, Windows Form… Secondary Forms Right click on project, choose Add, Windows Form… The developer may also create new secondary forms From the Solution Explorer, add a new Form to the project Add new form Multiform Applications November 17, 2018

Pre-built, modifiable About Box Secondary Form Ordinary Form Pre-built, modifiable About Box Give it a suitable name Multiform Applications November 17, 2018

Secondary Form The secondary form looks just like the main form initially Developer may add controls, write event handlers, and so forth in the same ways as with the primary form Multiform Applications November 17, 2018

Communicating Between Forms Primary creates an object of Secondary and displays it The primary and secondary forms are just objects of classes and they interact just like ordinary objects. Do not let the fact that they are form objects make them mysterious Passes Parameters to methods of Form2 Primary Form Secondary Form Return values and exposes public properties Primary knows about, creates, and uses secondary. Secondary knows NOTHING about primary. Multiform Applications November 17, 2018

Example: Communicating Between Forms Primary form sets some properties of secondary form Primary form instantiates an object of secondary form Primary form displays the secondary form . . . There is no difference in dealing with a developer-created form and a built-in dialog Multiform Applications November 17, 2018

Using Secondary Forms Can use Show or ShowDialog from one form to display an instance of another Modal dialog must be dismissed before continuing with the parent form Show yields a modeless dialog, while ShowDialog yields a modal dialog Modeless dialog does not “block” the parent and user may switch back and forth between them Multiform Applications November 17, 2018

Setting the Result of a Dialog Box The way a dialog box is closed, or its "result," can be set at either design time or run time: At design time, you can set the DialogResult property for the Button controls on a dialog box Setting the DialogResult property at run time allows you to dynamically handle user responses To set the DialogResult property for a control at design time: Click on the Button control whose property you want to set Select the DialogResult property in the Properties window and open the list of available property settings Select the appropriate DialogResult value Lecture 9 - CSCI 3800: Forms and Dialogs 11/17/2018

Setting Results of a Dialog Programmatically You can set the dialog box result for user-performed actions other than clicking a Button control. If your dialog box does not contain buttons to close the dialog box, you can set the result of the dialog box at run time. To set the DialogResult property for a control or form programmatically Navigate to the event handler or method in which you want to set the DialogResult property. Type code similar to the following: this.DialogResult = DialogResult.Yes; // OR – for a button btnNo.DialogResult = DialogResult.No; Although setting the DialogResult property will cause your dialog box to close automatically, you can still finish handling the control's Click event, and the dialog box will close once the event handler's code is completed. Lecture 9 - CSCI 3800: Forms and Dialogs 11/17/2018

Using a Secondary Form Typically, the logic of an application may dictate that one form may “own” another form in the sense that the first form decides when to create, show, and use the second form The first form often uses second form as result of some user action such as Selecting a choice (such as Open, Save, Print, Select Font, About, Help, and so forth) from a main Menu or a context Menu Clicking a button Selecting something from a ListBox or ComboBox The second form may also use secondary forms of its own In the event handler for the event that results in the display of the second form, an instance of the second form is created, and it is displayed through a call to a method such as Show or ShowDialog … Multiform Applications November 17, 2018

Creating and Using a Secondary Form From within an Event Handler in one Form, the code below may be used to create and display a second Form Create instance of the second form Display the second form Use results of work done by second form here in the first form Multiform Applications November 17, 2018

Using a Secondary Form In some cases, however, there may be a second form that is independent of all other forms No other form decides when to display it No other form creates an instance of it or uses its methods and properties A splash screen may be such a form In such a case, the secondary form may be “owned” by the application rather than by another form In this case, it may be opened by some method such as Main in the driver program Multiform Applications November 17, 2018

Independent Secondary Form Create and show splash screen form . . . … then, create and show the primary form for the application Note that these are sequential operations. The primary form will not be created and shown until the SplashForm has been closed Multiform Applications November 17, 2018

Replaceable picture in PictureBox Using the AboutBox VS provides a skeleton of an AboutBox form that is usable as it is, but it may also be tailored to suit the application These items are filled-in at run-time from AssemblyInfo.cs by the code that is provided Replaceable picture in PictureBox Multiform Applications November 17, 2018

Generated/Modified Code Description modified Default picture is replaced Multiform Applications November 17, 2018

AboutBox Example Results Multiform Applications November 17, 2018

Splash Screen One may remove the border and caption via the FormBorderStyle property if desired Ordinary form with a Split Container control docked to fill the form One Panel of the Split Container has a Picture Box Transparency may be achieved by setting the TransparencyKey property The other panel has a Label for the Program Name … … and another for the version number Uses a timer to dismiss itself Multiform Applications November 17, 2018

Transparent Borderless Form Remove the border from around the form Everything that is white in the design will be transparent when the form is displayed at run time Multiform Applications November 17, 2018

Borderless, Transparent Form Multiform Applications November 17, 2018

The Code in the Splash Screen Class Timer interval is set to 3.5 seconds in this case Multiform Applications November 17, 2018

Code in the Driver Primary form is not displayed until after the Splash Screen form closes itself Multiform Applications November 17, 2018