Lect Note On Chapter 1 - Event Driven Fundamentals
Lect Note On Chapter 1 - Event Driven Fundamentals
Chapter One
Ref - C# Programming by Barbara Doyle, page 27 and page 493
Chapter 1: Event Drive Fundamentals:
• What’s an event driven program?
• Working in the Programming Environment
• Building Your First Application
• Using the intrinsic controls
• Working with Properties, Methods, and Events
• Working with Projects in event driven Programming
Objectives:
• Describe an event driven program
• Describe the programming environment of windows based apps
• Identify the different parts and purpose of Visual Studio IDE.
• Describe windows form properties and events.
Overview of Event Driven Program (GUI
apps)
• A program can be Console app or Windows (GUI) app. Windows apps are event driven.
• An event is a notification (signal) that an action has occurred.
• Therefore, an event driven program is a programs that respond to user-initiated events such as mouse
clicks, keystrokes, timer expirations and touches and finger swipes (in smartphones).
• To understand what an event driven program, it is important to describe its mechanism in contrast
with Console applications.
• First, an event driven program is highly interactive, attractive, graphical user interface (GUI)
applications that interact differently with the operating system.
• With console applications, the program calls on the operating system to perform certain functions such as
inputting or outputting of data.
• Of course, for both Windows and console applications, execution begins with the first statement in the Main( )
method.
• with a Windows application, instead of the program executing sequential statements from top to bottom, the
application, once launched, register events with the operating system, and sits in what is called a process loop
waiting for an event to execute.
• When the event occurs, Windows applications receive messages from the operating system that an event has
occurred. You write methods called event handlers to indicate what should be done when an event such as a
mouse click on a button or the press of a key occurs.
• Unlike console-based applications that exit after all statements have
been sequentially executed, Windows-based applications, after they
are launched, sit idly waiting for notification of a registered event. The
program remains in the operating system environment in a process
loop.
• The Windows applications you will be creating will always refer to the System.Windows.Forms
namespace.
• Visual Studio automatically adds this reference when you select the C# Windows Forms Application template,
and it makes available for you the data types or classes needed to create a Windows Application Project.
2. public class Form1 : Form // Line 2 - the class heading definition looks a little different from what you have
seen in Java. It includes not only the class name, but a colon followed by another class name. This is
how a derived class in C# defined. Form is the base class; and Form1 is the derived class. Look the
statement at line 2 closely again.
• The colon (:) is used in the definition to indicate that the new class being defined, Form1, is derived from a base
class named System.Windows.Forms.Form. The default name given for a Windows application class in Visual Studio is Form1.
• Formis a predefined .NET class that includes a number of methods and
properties used to create a basic Windows screen. So as you learnt in OOP
course, Form1 inherits the characteristics of the Form class.
• If you examine the form created below, it includes fully functional
Close, Minimize, and Maximize buttons in the upper-right corner of
the form. No new code had to be written to add these features.
• Form1 inherited this functionality from the Form class. Remember that
one of the beauties of object-oriented programming is not having to
reinvent the wheel. Inheriting characteristics from base classes adds
functionality to your program without the burden of your having to
do additional coding.
Reading assignment
Elements of a Good Design (read page 500 – 502 of C# Programming by Barbara Doyle)
• As you start developing Windows applications, your goal should be to develop
applications that are usable, that permit users to spot items in the windows
quickly, and that enable users to interact with your program.
• Appearance matters! An attractively laid out screen with good visual organization
gives users control. This is of utmost importance.
• A few of the more important HCI considerations in developing Windows
applications are:
• Consistency,
• alignment,
• avoid-clutter,
• color, and
• target-audience.
Additional reading
Visual Programming
• Visual Studio enables you to use C# as a visual programming
language—in addition to writing program statements to build
portions of your apps, you’ll also use Visual Studio to drag and drop
predefined GUI objects like buttons and textboxes into place on your
screen, and label and resize them. Visual Studio will write much of the
GUI code for you.
C# on Non-Windows Platforms
• Microsoft originally developed C# for Windows development, but it
can be used on other platforms via the Mono Project and .NET Core
—both managed by the .NET Foundation. For more information, see
http://www.dotnetfoundation.org/
• Today’s apps can be written with the aim of communicating among
the world’s computers. As you’ll see, this is the focus of
Microsoft’s .NET strategy. Later in the book, you’ll build web-based
apps with C# and Microsoft’s ASP.NET technology.
About the Microsoft’s .NET