Windows Desktop Applications

Slides:



Advertisements
Similar presentations
Microsoft Excel. Click on “Start,” then “Microsoft Office Excel.”
Advertisements

CS0004: Introduction to Programming Visual Studio 2010 and Controls.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Chapter 1: An Introduction to Visual Basic 2005 Programming with Microsoft Visual Basic 2005, Third Edition.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Understanding Microsoft Excel
The New User Interface MEDITECH Training & Education.
Dive Into® Visual Basic 2010 Express
Chapter 1: An Introduction to Visual Basic .NET
Visual Basic .NET BASICS
Visual Basic.NET Windows Programming
Understanding Microsoft Excel
Chapter 9 Programming Based on Events
Chapter 2: The Visual Studio .NET Development Environment
Chapter 1: An Introduction to Visual Basic 2015
Chapter Topics 15.1 Graphical User Interfaces
Chapter 8: Writing Graphical User Interfaces
Chapter 2 – Introduction to the Visual Studio .NET IDE
An Introduction to Computers and Visual Basic
Variables and Arithmetic Operations
3.01 Apply Controls Associated With Visual Studio Form
Program and Graphical User Interface Design
Chapter Eleven Handling Events.
3.01 Apply Controls Associated With Visual Studio Form
Reference: COS240 Syllabus
Visual studio 2010 SENG 403, Tutorial 2 SENG Winter 2011.
An Introduction to Computers and Visual Basic
Using Procedures and Exception Handling
Chapter 2 Visual Basic Interface
Controls, Events, and More
Program and Graphical User Interface Design
Event Driven Programming
Chapter 7 Advanced Form Techniques
Understanding Microsoft Excel
Variables and Arithmetic Operations
Visual Basic..
Multi-form applications and dialogs
MODULE 7 Microsoft Access 2010
Building an Application in the Visual Basic .NET Environment
Introduction To Microsoft PowerPoint 2007
An Introduction to Computers and Visual Basic
Chapter 15: GUI Applications & Event-Driven Programming
6. WinForms 2003 C# GUI - Basics.
European Computer Driving Licence
Understanding Microsoft Excel
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

Windows Desktop Applications Windows Forms Windows Forms September 18, 2018

Windows Desktop Applications Windows Desktop Applications are implemented in C# using Windows Forms There are .NET classes that represent windows, buttons, text boxes, menus, list boxes, and so forth With experience, they are very easy to use: Drag and Drop from the “toolbox” Set properties Handle events Windows Forms September 18, 2018

Event Driven Programming Console applications are essentially sequential code executed in the order specified by Main and whatever it calls Windows programs are event-driven Main instantiates a main window Subsequently, the order of code execution is primarily determined by events, many of which are triggered from outside the code User clicks a mouse User presses a key, producing keystroke User scrolls Timer expires I/O operation concludes And so forth Windows Forms September 18, 2018

Events During the execution of a Windows program, thousands of events typically occur Every time the mouse is moved by one pixel over the window, a MouseMove event occurs, for example Each time an event related to the program occurs, the program is notified by the system. It may Take some action Ignore the event and let Windows deal with it Windows ignores most events but not all It typically doesn’t ignore a CTRL-ALT-DELETE event, for example Windows Forms September 18, 2018

Dealing with Events Programs typically ignore most events The events to which a program responds and the action it takes give the program its behavior The program may provide one or more methods that execute actions to “do something” in response to the event Such a method is called an event handler An event handler is a method with a signature similar to this private void HandlerName (Object sender, EventArgs e) Windows Forms September 18, 2018

Delegates While it is not necessary to understand delegates to understand event-driven programming, the term delegate occurs frequently in the literature The delegate is a type that defines a signature, that is, the return value type and parameter list types for a method You can use the delegate type to declare a variable that can refer to any method with the same signature as the delegate As indicated on the previous slide an EventHandler delegate has the signature: public delegate void EventHandler(Object sender, EventArgs e); Any method with the same signature can serve as an EventHandler Windows Forms September 18, 2018

Event Handlers Registering an event-handler in C# is analogous to Adding a Listener in Java Event handlers are “registered” for events to be handled this.Load += new System.EventHandler (Form_Load); Visual Studio generates the code to register most event handlers so that the programmer need not do so in most cases Delegate Event Handler method name which must have same signature as the EventHandler delegate Load is the event name Windows Forms September 18, 2018

Windows Form Application Create a Windows Forms Application … … with an appropriate name Windows Forms September 18, 2018

Visual Editor for the Form – Form can be resized, etc. Results The Window Driver Program Rename the Form class Visual Editor for the Form – Form can be resized, etc. Rename Driver Windows Forms September 18, 2018

Main Program No changes or additions to Main program are required for simple Windows Form applications Windows Forms September 18, 2018

Easily switch between the views Design and Code Views Code View Windows derived from Form class like Java GUI window derived from JFrame Easily switch between the views Design View Windows Forms September 18, 2018

Design View and Toolbox Controls in the Toolbox are represented by .NET classes Dragging and dropping a control onto the form creates an object of the class in the code The control may be placed at a desired location on the form and sized to suit your needs Standard controls can be placed on a form Windows Forms September 18, 2018

Each Form has Two Code Files Windows Forms September 18, 2018

Each Form Has 3 Files These represent the C# code, the designer code file, and the visual components of the form In you plan to copy a form and paste it into another project, be sure to copy all 3 of the files Windows Forms September 18, 2018

Note the generated code for registering this event handler Designer.cs The designer code file contains VS-generated code that defines the controls dropped on the form and their properties, including their event handler registrations Note the generated code for registering this event handler Windows Forms September 18, 2018

Properties of Controls Each control has an extensive list of properties that allows the designer/programmer to manage many of the features of the control such as Colors Fonts Size Style Object name Caption (Text) Many more Windows Forms September 18, 2018

Setting Properties of Controls Properties can be set or retrieved At design time in the Design View Changes show up both in the visual editor and in the code files Changes in the visual editor change the properties and change the code Changes in the code may change the properties and the visual appearance in the editor (depending on whether the code is “definition” code or to be executed at run time) At run time – via program code Windows Forms September 18, 2018

Design Time: Setting Properties of Controls Object name in code Button caption Background color of Button Text Alignment Font Color Is button visible? Font Windows Forms September 18, 2018

Editing Properties: Example Windows Forms September 18, 2018

Properties in Code After changing the properties, VS has added code to the Designer file to make the changes Windows Forms September 18, 2018

Making Simultaneous Changes to Multiple Controls Drag a rectangle around desired controls Change properties that are in common to the selected controls Can see the results All included controls are selected The one with white handles is the “master” Windows Forms September 18, 2018

Controls Toolbar Send to Front or Back Windows Forms September 18, 2018

Align and Size Controls With all buttons selected, use the toolbar to align and resize them appropriately The entire form also has properties to set Made same size, aligned vertically, centered horizontally Windows Forms September 18, 2018

Form Properties Windows Forms September 18, 2018

Form Properties Designate a button to be activated by pressing the <ENTER> key Designate a button to be activated by pressing the <ESC> key Windows Forms September 18, 2018

Form Properties Specify where window appears on screen Center the window on the screen Neither maximized nor minimized originally Windows Forms September 18, 2018

Complete Form with More Controls Textboxes – all set to right-aligned text because they are for numeric input; last is read-only Align groups of controls to make the form look professional Label controls Windows Forms September 18, 2018

Tab Order For controls such as TextBoxes and Buttons that can have the keyboard focus, there is a tab order than one can set to control the order in which the controls receive focus as the tab key is pressed repeatedly Windows Forms September 18, 2018

Not clicked since focus cannot be on a read-only control Tab Order Click in the order you want focus to move. The Label for a TextBox should be clicked just before the TextBox Not clicked since focus cannot be on a read-only control Windows Forms September 18, 2018

Cursor is here, right-justified initially Tab Order Run the application and this window will appear Cursor is here, right-justified initially 2 If tab is pressed multiple times focus will move in the order of the numbers 3 4 5 Windows Forms September 18, 2018

Current Status At this point, the program runs successfully but does very little We can see the form We can type into the two input textboxes We can click buttons Nothing happens if we do these things This is all of the “code behind” the form at this point Windows Forms September 18, 2018

Handling Some Events Three primary events we need to handle are the click events for the 3 buttons In the Design View, we double click each button A skeleton of the Event Handler for each button is written in the “code behind” .cs file Each Event Handler is registered in the designer.cs file Windows Forms September 18, 2018

Event Handler Skeletons 3 event handler skeletons added Event Handler registered Windows Forms September 18, 2018

Add Event Handler Code For the Quit button, we want to exit the program For the Clear button, we want to make the text boxes empty and set the focus to the first text box Run the program and observe how the Quit and Clear buttons work Windows Forms September 18, 2018

The Calculate Button Handler When Calculate is pressed, we want to get the points and hours values from the form and divide to calculate GPA Convert to decimal if possible Calculate GPA Else, show error message, reset form, and exit If OK so far, display result Windows Forms September 18, 2018

Errors The TryParse method takes care of some of the input errors a user may make Empty input fields Non-numeric input It does not handle others such as Entering 0 for the number of Hours Earned (divide by 0 error) Producing a GPA of 57.2 or other invalid value We must add code to handle the other anomalies Windows Forms September 18, 2018

Edited Handler Windows Forms September 18, 2018

Other Events One may wish to display a “Goodbye” message when the application ends Can be done in the btnQuit_Click handler for that approach to quitting the application but there are … Other ways to quit Red X System Menu Close Alt-F4 Use FormClosing event to catch them all at once Windows Forms September 18, 2018

Closing Event In the Design View, click on the lightning bolt in Properties to get a list of all Events for the form Double-Click FormClosing Events Windows Forms September 18, 2018

Get current date and format it for display as “Thursday, June 5, 2014” Load Event Just before the window becomes visible for the first time, the Load event is recognized It gives the programmer a chance to do some things at run time just before the window is shown For example, we might want to do something like: Display date and time Display info about the application such as title, author, version, etc. Give initial values to some controls Set window caption Get current date and format it for display as “Thursday, June 5, 2014” Windows Forms September 18, 2018