Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Lect Note On Chapter 1 - Event Driven Fundamentals

Uploaded by

beshahashenafi32
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Lect Note On Chapter 1 - Event Driven Fundamentals

Uploaded by

beshahashenafi32
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Event Drive 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.

• Another important difference in a Windows application is that unlike


the sequential nature you can plan on with console-based
applications, in which one statement executes and is followed by the
next, no sequential order exists with event-handling methods for
Windows applications.
• If you have many options (buttons), you do not know which one the user will
click first or whether any of them will be clicked.
• With Windows applications, many different types of events can be fired.
• As a developer, you select actions your program should respond to and write event
handlers for those events.
• If you have five buttons on the screen, button1might not be the one clicked first
every time. These event-handler methods can be executed in a different order
every time your application runs.
• Windows applications not only function differently, they also look
different.
• Windows applications tend to have a consistent user interface—one that is
considered more user friendly than what you find with console-based applications.
• Note - the user interface of a Windows application is considered as important as
the application’s power behind the scenes.
• A graphical user interface (GUI) can include menus, buttons, pictures, and
text in many different colors and sizes. Think of the form as a container
waiting to hold additional controls, such as buttons or labels.
The Programming Environment
• Windows-based GUI applications are displayed on a Windows form. Form
is a container that hold additional controls, such as buttons, labels, etc.
• Controls are objects that can display and respond to user actions.
• For example, buttons, labels, etc.
• The code for windows app can be edited on Notepad, But, this is not
recommended for developing Windows-based applications, because
building Windows-based applications is a complicated endeavor.
• it is recommended to use Visual Studio integrated development environment
(IDE).
• Visual Studio IDE is a tool:
• contain the .NET Framework class library - has the entire subsystem of classes
that enables to create highly interactive, attractive, GUI applications.
• it is easy to perform drag-and-drop constructions
• Actually - the program listing in the example below is much smaller than what is generated
from Visual Studio.
• The Visual Studio IDE automatically generates all the code needed for
a blank Windows form for you.
• Not using this IDE means you lose out on the built-in, drag-and-drop
construction capabilities and the ease of modifying controls during design.
• Development time for Windows applications is greatly reduced when
you use Visual Studio and C#, because it is easy to add controls by
dropping and dragging them onto the form container.
Examining the code generated
• Before going further, let us see what is actually required to create a Windows application in C#.
Examine the statements below.
1. Notice that the using directive labeled Line 1 imports types or classes from the System.Windows.Forms
namespace.
• Most of the classes for developing Windows-based applications are organized here.
• By including this directive, you avoid having to fully qualify references to classes organized under the
System.Windows.Forms namespace.

• 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

• In 2000, Microsoft announced its .NET initiative (www.microsoft.com/net), a


broad vision for using the Internet and the web in the development,
engineering, distribution and use of software. Rather than forcing you to use
a single programming language, .NET permits you to create apps in any .NET-
compatible language (such as C#, Visual Basic, Visual C++ and many others).
Part of the initiative includes Microsoft’s ASP.NET technology for building
web-based applications.
.NET Framework
• The .NET Framework Class Library provides many capabilities that you’ll use
to build substantial C# apps quickly and easily. It contains thousands of
valuable prebuilt classes that have been tested and tuned to maximize
performance. You’ll learn how to create your own classes, but you should re-
use the .NET Framework classes whenever possible to speed up the
software-development process, while enhancing the quality and
performance of the software you develop.
Common Language Runtime
• The Common Language Runtime (CLR), another key part of the .NET
Framework, executes .NET programs and provides functionality to
make them easier to develop and debug. The CLR is a virtual machine
(VM)—software that manages the execution of programs and hides
from them the underlying operating system and hardware. The source
code for programs that are executed and managed by the CLR is
called managed code. The CLR provides various services to managed
code, such as
 integrating software components written in different .NET languages,
 error handling between such components,
 enhanced security,
 automatic memory management and more.
• Unmanaged-code programs do not have access to the CLR’s services,
which makes unmanaged code more difficult to write. Managed code
is compiled into machine-specific instructions in the following steps:
1. First, the code is compiled into Microsoft Intermediate
Language (MSIL). Code converted into MSIL from other languages and
sources can be woven together by the CLR—this allows programmers
to work in their preferred .NET programming language. The MSIL for an
app’s components is placed into the app’s executable file—the file that
causes the computer to perform the app’s tasks.
2. When the app executes, another compiler (known as the just-
in-time compiler or JIT compiler) in the CLR translates the MSIL in the
executable file into machine-language code (for a particular platform).
3. The machine-language code executes on that platform.
Platform Independence
• If the .NET Framework exists and is installed for a platform, that platform can run any .NET
program. The ability of a program to run without modification across multiple platforms is
known as platform independence. Code written once can be used on another type of
computer without modification, saving time and money. In addition, software can target a
wider audience. Previously, companies had to decide whether converting their programs to
different platforms—a process called porting—was worth the cost. With .NET, porting
programs is no longer an issue, at least once .NET itself has been made available on the
platforms.Language Interoperability
• The .NET Framework provides a high level of language interoperability. Because software
components written in different .NET languages (such as C# and Visual Basic) are all
compiled into MSIL, the components can be combined to create a single unified program.
Thus, MSIL allows the .NET Framework to be language independent.
• The .NET Framework Class Library can be used by any .NET language. The latest release
of .NET includes .NET 4.6 and .NET Core:
• NET 4.6 introduces many improvements and new features, including ASP.NET 5 for web-based
applications, improved support for today’s high-resolution 4K screens and more.
• .NET Core is the cross-platform subset of .NET for Windows, Linux, OS X and FreeBSD.
End of Chapter One

You might also like