C# & Windows GUI Applications: IT 3334: Integrative Programming and Techniques
C# & Windows GUI Applications: IT 3334: Integrative Programming and Techniques
C# & Windows GUI Applications: IT 3334: Integrative Programming and Techniques
and Techniques
C#
&
Windows
GUI Applications
Lecture Contents
• Windows Forms
• Events
• Controls
INTEGRATIVE
PROGRAMMING
&
TECHNIQUES
4
Chapter 9
C# Programming:
From Problem Analysis to Program Design
4th Edition
Contrasting Windows and Console
Applications
6
Contrasting Windows and Console
Applications by Functionality
• Console applications
– Each line in Main( ) executed sequentially –
then the program halts
• Windows applications
– Once launched, sits and waits for an event
– Sits in a process loop
• Event: notification from operating system
that an action, such as the user clicking the
mouse or pressing a key, has occurred
– Write event-handler methods for Windows apps7
C# Programming: From Problem Analysis to Program Design
Graphical User Interfaces
• Windows applications also look different
from console applications
• Interface: front end of a program
– Visual image you see when you run a program
• Graphical user interface (GUI) includes:
– Menus
– Text in many different colors and sizes
– Other controls (pictures, buttons, etc.)
C# Programming: From Problem Analysis to Program Design 8
Windows Applications
• Reference and import
System.Windows.Forms namespace
• Class heading definition
– Includes not only the class name, but a colon
followed by another class name
• Derived class (first class), Base class (second class)
• public class Form1 : Form
• Derived classes inherit from base class
•C# Programming:
No multiple inheritance within .NET
From Problem Analysis to Program Design 9
languages
Windows Applications (continued)
• Text - property of the Form class
– A property for setting/getting title bar caption
– Can be used in constructor
• Windows forms/controls offer many properties
including Text, Color, Font, and Location
• Execution begins in Main( ) method
– Main( ) is located in Program.cs file for the application
– Call to Run( ) method places application in process loop
Output
generated
from
Windows0
application
Select
File
New Windows
Project Forms Browse
Application to
template location
to store
your
Name
work
Properties
Window
• Windows Forms
–Properties
–Events
Windows Forms
• Extensive collection of Control classes
• Top-level window for an application is called a
Form
• Each control has collection of properties and
methods
– Select property from an alphabetized list (Properties
window)
– Change property by clicking in the box and selecting
or typing the new entry at design time.
• C#Each control
Programming: has
From Problem collection
Analysis to Program Designof events. 19
Windows Form Properties
Property value
Properties
• Events
Windows Form Events
• Add code to respond to events, like button clicks
– Code goes into Form1.cs file
Events
button
selected
• Controls
Controls
• Controls are all classes
– Button, Label, TextBox, ComboBox, MainMenu,
ListBox, CheckBox, RadioButton, and
MonthCalendar
• Each comes with its own predefined
properties and methods
• Each fires events
• Each is derived from the
System.Windows.Forms.Control class
C# Programming: From Problem Analysis to Program Design 35
Controls (continued)
Add Label
objects to
Form
object…
Use
options on
FORMAT
menu
{
}
AcceptButton
property on the
form
was set to
btnCompute