0% found this document useful (0 votes)
38 views

EDP_CHAP_2

Uploaded by

Dinksraw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

EDP_CHAP_2

Uploaded by

Dinksraw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 65

Event Driven Programming

Chapter 2- Introduction to.NET

By: Ins. Solomon S. 1


o The .NET Platform and Its Architecture
- Base Class Library
- Common Language Runtime
o Uses of .NET Platform in Application
Development
o Introduction to Microsoft Visual
Studio 2010
- SDI and MDI Forms
- Controls
What is .NET Framework?

o.NET Framework (pronounced dot net) is a


software framework developed by Microsoft that
runs primarily on Microsoft Windows.
oThe .NET framework is Internet-oriented.
o.NET Framework is a complete environment that

allows developers to develop, run, and deploy the


following applications:
 Console applications
 Windows Forms applications
 Windows Presentation Foundation (WPF)

applications
 Web applications (ASP.NET applications)
 Web services
 Windows services
 Workflow-enabled applications using Windows

Workflow Foundation (WF)


o .NET Framework also enables a developer to create
sharable components to be used in distributed
computing architecture .
o . NET Framework supports the object-oriented
programming model for multiple languages, such as
Visual Basic, Visual C#, and Visual C++.
o .NET Framework supports multiple programming
languages in a manner that allows language
interoperability.
o This implies that each language can use the code
written in some other language.
o The first level of the representation is the operating
system the .NET layer is located between the system and
applications.
o The second level is the Common Language
Runtime(CLR), which provides the part of the .NET
Framework doing the most work.
o The next level is the Base Class Library (BCL), which
provides all .NET objects that can be used both in your
code and by Visual C# when creating applications.
o The last level is represented by applications that rely on
the previous layers.
o .NET Framework provides enormous advantages to
software developers in comparison to the advantages
provided by other platforms.
o Microsoft has united various modern as well as existing
technologies of software development in .NET
Framework.
o These technologies are used by developers to develop
highly efficient applications for modern as well as future
business needs.
o .NET Framework Class Library
o Common Language Runtime
o Dynamic Language Runtimes (DLR)
o Application Domains
o Runtime Host
o Common Type System
o Cross-Language Interoperability
o .NET Framework Security
o Side-by-Side Execution
o The .NET Framework is shipped with compilers of all .NET
programming languages to develop programs.
o There are separate compilers for the Visual Basic, C#, and
Visual C++ programming languages in .NET Framework
o Each .NET compiler produces an intermediate code after
compiling the source code.
o The intermediate code is common for all languages and is
understandable only to .NET environment.
o This intermediate code is known as MSIL
Intermediate Language:-
o is also known as MSIL (Microsoft Intermediate Language)

or CIL (Common Intermediate Language).


oAll .NET source code is compiled to Intermediate Language

(IL).
oIL is then converted to machine code at the point where the

software is installed, or at run-time by a Just-In-Time (JIT)


compiler.
o Provides an infrastructure that is common to all .NET
languages.
o CLR provides an environment to execute .NET applications
on target machines.
o CLR provides services to executing programs.
o Traditionally, different programming environments have
different runtimes.
o Examples of runtimes include the standard C library,
the Visual Basic runtime, and the Java Virtual
Machine (JVM).
o The code which runs under the CLR is called as Managed
Code.
o Programmers need not to worry on managing the memory
if the programs are running under the CLR as it provides
memory management and thread management.
o Programmatically, when our program needs memory, CLR
allocates the memory for scope and de-allocates the
memory if the scope is completed.
o CLR is also a common runtime environment for all .NET
code irrespective of their programming language, as the
compilers of respective language in .NET Framework
convert every source code into a common language
known as MSIL or IL (Intermediate Language).
o CLR also provides various services to execute processes,
such as memory management service and security
services.
o The responsibilities of CLR are listed as follows:
 Automatic memory management

 Garbage Collection

 Code Access Security

 Code verification

 JIT compilation of .NET code


The CLR provides the following
benefits:
Performance improvements.
The ability to easily use components developed in other

languages.
Extensible types provided by a class library.

Language features such as inheritance, interfaces, and

overloading for object-oriented programming.


Support for structured exception handling.

Support for custom attributes.

Garbage collection.
o Managed code:- is the code that is executed directly by
the CLR instead of the operating system.
o The code compiler first compiles the managed code to
intermediate language (IL) code, also called as MSIL code.
o This code doesn't depend on machine configurations and
can be executed on different machines.
• In the managed code, since the execution of the code is
governed by CLR, the runtime provides different services,
such as garbage collection, type checking, exception
handling, and security support.
o These services help provide uniformity in platform and
language-independent behavior of managed code
applications.
The execution process for managed code.
A piece of managed code is executed as follows:
o Choosing a language compiler

o Compiling the code to MSIL

o Compiling MSIL to native code

o Executing the code.


o Unmanaged code:- is the code that is executed directly by
the operating system outside the CLR environment.
o It is directly compiled to native machine code which
depends on the machine configuration.
o In the unmanaged code, the allocation of memory, type
safety, and security is required to be taken care of by
the developer.
o What is the role of the JIT compiler in .NET
Framework?
 The JIT compiler is an important element of CLR.
 which loads MSIL on target machines for execution.
 The MSIL is stored in .NET assemblies after the developer
has compiled the code written in any .NET-compliant
programming language, such as Visual Basic and C#.
 JIT compiler translates the MSIL code of an assembly and
uses the CPU architecture of the target machine to execute
a .NET application
o It also stores the resulting native code so that it is
accessible for subsequent calls.
o If a code executing on a target machine calls a non-native
method, the JIT compiler converts the MSIL of that method
into native code.
o This is also called as Base Class Library.
o It is common for all types of applications i.e. the way you
access the Library Classes and Methods in VB.NET will be
the same in C#
o It is common for all other languages in .NET.
o The .NET Framework class library is huge, comprising
more than 2,500 classes.
o All this functionality is available to all the .NET languages.
The .NET Framework Class Library consists of four main parts:
1.Base class library (which includes networking, security,
diagnostics, I/O, other types of operating system services)
2. Data and XML classes
3.Windows UI(user interface)
4.Web services and Web UI
The following are different types of applications that can make use
of .NET class library.
1.Windows Application.
2.Console Application
3.Web Application.
4.XML Web Services.
5.Windows Services.
Uses of .NET Platform in Application
Development

Assignment
Introduction to Microsoft
Visual Studio
 Visual programming is the creation of a computer
program by utilizing pictorial elements. ex. Visual C#.
 Visual programming language (VPL) is any programming
language that lets users create programs by manipulating
program elements graphically rather than by
specifying them textually.
 A VPL allows programming with visual expressions, spatial
arrangements of text and graphic symbols, used either as
elements of syntax or secondary notation.
 User friendly & interactive using integrated
development environment (“IDE“).
 Support rapid application development

 Allows rapid design and prototype of Windows

applications
 Provide an effective development communication tool

 Easy to develop graphical user interfaces

 Multiple vendor support


o Most visual basic .NET is an Event driven program that
communicates with the users through GUI.
o That means users employ the GUI objects to select options,
to enter data, and cause events to occur.
o Graphical User Interface - consists of graphical objects
such as icons that are used by the end user to interact with
the operating system.
o The most famous GUI program is the Microsoft Windows
desktop.
o Visual C# is an integrated development environment (IDE) and
programming language developed by Microsoft.
o It is primarily used for building Windows applications, web services,
and applications for the .NET framework.
o Key Features
 Language: C#, It is designed for building a variety of applications that run
on the .NET framework.
 IDE: Visual Studio is the main IDE used for developing in Visual C#.
 Framework: Visual C# is closely tied to the .NET framework, which
provides a large library of pre-coded solutions for common programming
tasks, enabling rapid application development.
 Versatility: You can use Visual C# for:
 Desktop applications (Windows Forms, WPF)
 Web applications (ASP.NET)
 Mobile applications (Xamarin)
 Game development (Unity)
o Visual basic .NET allows developers to create windows
applications with a graphical user interface.
o windows graphical user interface provides visual cues such as
menus, button, and icons that allows a user to enter data and
instruction into a computer .
o Both windows and console application are called stand-alone
application .
o A stand –alone application is an application that does not
requires other applications or data sources to run in the
operating system.
o Open Visual Studio.
o Create a New Project:
 Go to File > New > Project.
 Select C# from the left pane.
 Choose Windows Forms Application.
 Name your project (e.g., MyFirstC#App) and click OK.
o Familiarize yourself with the IDE layout:
 Solution Explorer: Shows your project files.
 Properties Window: Displays properties of selected objects.
 Toolbox: Contains controls you can add to your form.
 Code Editor: Where you write your code.
o Select the Form: Click on the form in the designer.
o Open the Properties Window: If it’s not visible, go to
View > Properties Window.
o Set Properties:
 For example, set Text to "My First C# Application".
 Change the BackColor to a color of your choice.
 Open the Toolbox: If it’s not visible, go to View > Toolbox.
 Drag a Control: For example, drag a Button onto the form.
 Set Button Properties:
o Click on the button to select it.
o In the Properties Window, set Text to "Click Me".
 Double-click the Button: This opens the Code Editor with
an event handler for the button click.
 Add Code:
SDI and MDI Forms
o A program that can only support one open window or a
document.
o Create one instance of a particular form.
o SDIs can open only a single document at a time.
o For Example, paint and Notepad are SDI’s
o Notepad is an example of an SDI application (If you want
multiple documents open, you simply run Notepad multiple
times.)
o Although Notepad is text-based, an SDI can be any type of
application: text, graphics, spreadsheet, anything.
o Therefore, to create an SDI, start from a normal form, add a
menu to it, and configure it to do what you want.
Single Document Interface (SDI)
o MDI programs enable users to edit multiple documents at
once.
o Usually more complex than single-document-interface
applications.
o EX. Photoshop ,Excel and Adobe Acrobat Reader are MDI’s.

Multiple Document Interface


(MDI)

MDI parent and MDI child.


o The application window of an MDI program is called the
parent window.
o Each window inside the application is referred to as a child
window.
o MDI:-Allows multiple windows
• Parent window- Application window
- Can have many child windows
• Child window- Cannot be parent
– Has exactly one parent
– Cannot be moved outside parent
– Functionality can be different than other child
windows from same parent.
o An object is a type of user interface element you create
on a Visual Basic form by using a toolbox control.
o In Visual Basic, the form itself is an object.
o Every Visual Basic control consists of three important
elements:
o Properties: which describe the object,
o Methods: cause an object to do something and
o Events: are what happens when an object does something.
o All the Visual Basic Objects can be moved, resized or
customized by setting their properties.
o A property is a value or characteristic held by a Visual

Basic object, such as Caption or Fore Color.


o Properties can be set at design time by using the

Properties window or at run time by using statements in


the program code.
Object . Property = Value
Where,
Object: is the name of the object you're customizing.
Property: is the characteristic you want to change.
Value: is the new property setting
o VB.Net provides a huge variety of controls that help you to
create rich user interface.
o Functionalities of all these controls are defined in the
respective control classes.
o The control classes are defined in the
System.Windows.Forms namespace.
o Forms: The container for all the controls that make up
the user interface.
o TextBox:
• It represents a Windows text box control.
• When user want to type some input use a text box.
• used to add text or to display text in a form.
o The following are some of the commonly used properties
of the TextBox control:
 CharacterCasing: Gets or sets whether the TextBox
control modifies the case of characters as they are typed.
 Font: Gets or sets the font of the text displayed by the
control.
 ForeColor: Gets or sets the foreground color of the
control.
 Lines: Gets or sets the lines of text in a text box control.
 Multiline Gets or sets a value indicating whether this is a
multiline TextBox control.
6.PasswordChar: Gets or sets the character used to mask
characters of a password in a single-line TextBox control.
7. ReadOnly: Gets or sets a value indicating whether text in
the textbox is read-only.
8. Text: Gets or sets the current text in the TextBox.
9. TextAlign Gets or sets how text is aligned in a TextBox
control. This property has values:
Left
Right
Center
10. AutoSize: Enables automatic resizing based on font size
for single-line edit controls.
o The following are some of the commonly used methods of
the TextBox control:
1. AppendText: Appends text to the current text of a text
box.
2. Clear: Clears all text from the text box control.
3. Copy: Copies the current selection in the text box to the
Clipboard.
4. Cut: Moves the current selection in the text box to the
Clipboard.
5. Paste: Replaces the current selection in the text box with
the contents of the Clipboard.
6. Undo: Undoes the last edit operation in the text box.
o The following are some of the commonly used events of
the Text control:
1. Click: Occurs when the control is clicked.
2. DoubleClick: Occurs when the control is double-clicked.
3. TextAlignChanged: Occurs when the TextAlign property
value changes.
o Label:
• It represents a standard Windows label.
• is usually used to display text that cannot be edited by the
user during runtime.
• But using the properties or code that is displayed can be
changed.
o The following are some of the commonly used properties
of the Label control:
1.Autosize: Gets or sets a value specifying if the control
should be automatically resized to display all its contents.
2. BorderStyle: Gets or sets the border style for the control.
3. Font: Gets or sets the font of the text displayed by the
control.
4. ForeColor: Gets or sets the foreground color of the
control.
5. Text: Gets or sets the text associated with this control.
6. TextAlign: Gets or sets the alignment of text in the label.
o The following are some of the commonly used methods of
the Label control:
1. Refresh: Forces the control to invalidate its client area and
immediately redraw itself and any child controls.
2. Select: Activates the control.

3. Show: Displays the control to the user.

Events of the Label Control


1. Click: Occurs when the control is clicked.
2. DoubleClick: Occurs when the control is double-clicked.

3. GotFocus: Occurs when the control receives focus.

4. TextChanged: Occurs when the Text property value


changes.
o Button:
• It represents a Windows button control.
• is used to trigger some action for the form.
• It is generally used to generate a Click event by providing a
handler for the Click event.
Properties of the Button Control
o The following are some of the commonly used properties of the Button
control:
1. AutoSizeMode: Gets or sets the mode by which the
Button automatically resizes itself.
2. BackColor: Gets or sets the background color of the
control.
3. BackgroundImage: Gets or sets the background image
displayed in the control.
4. ForeColor: Gets or sets the foreground color of the control.
5. Image: Gets or sets the image that is displayed on a button
control.
6. Text: Gets or sets the text associated with this control.
oList Box:
•is used to display a list of items, from which the user can
select single or multiple choices by clicking on them.
•It allows the programmer to add items at design time by

using the properties window or at the runtime.


1. BorderStyle: Gets or sets the type of border drawn
around the list box.
2. Items: Gets the items of the list box.
3. MultiColumn: Gets or sets a value indicating whether the
list box supports multiple columns.
4. Text: Gets or searches for the text of the currently
selected item in the list box.
5. Sorted: Gets or sets a value indicating whether the items
in the list box are sorted alphabetically.
6. SelectionMode: Gets or sets the method in which items
are selected in the listbox. This property has values:
None, One MultiSimple, MultiExtended
o ComboBox:
• It represents a Windows combo box control.
• is used to display a drop-down list of various items.

• It is a combination of a text box in which the user enters an

item and a drop-down list from which the user selects an


item.
• Properties of the ComboBox Control

1. Sorted: Gets or sets a value indicating whether the items


in the combo box are sorted.
2. Text: Gets or sets the text associated with this control.
3. Items: Gets an object representing the collection of the
items contained in this ComboBox.
4. MaxDropDownItems: Gets or sets the maximum number
of items to be displayed in the drop-down part of the combo
box.
5. FlatStyle: Gets or sets the appearance of the ComboBox.
6. MaxLength: Gets or sets the maximum number of
characters a user can enter in the editable area of the combo
box.
oRadioButton:
•It
enables the user to select a single option from a group of
choices when paired with other RadioButton controls.
1. Appearance: Gets or sets a value determining the appearance of the
radio button.
2. Check Align: Gets or sets the location of the check box portion of the
radiobutton.
3. Checked: Gets or sets a value indicating whether the control is
checked.
4. Text: Gets or sets the caption for a radio button.
o CheckBox:
• It represents a Windows CheckBox.
• is used to select the choice by checking or not checking a
check box.
• When a check box is selected it has the value True, and
when it is cleared, it holds the value False.
1. Appearance: Gets or sets a value determining the
appearance of the checkbox.
2. CheckAlign: Gets or sets the horizontal and vertical
alignment of the checkmark on the check box.
3. Checked: Gets or sets a value indicating whether the
check box is selected.
4. CheckState: Gets or sets the state of a check box.
5. Text: Gets or sets the caption of a check box.
o PictureBox:
• is used to display an image of the file formats like png, gif,
jpeg, bmp, wmf, ico, pcx, tga, tiff.
• Images can be loaded either at the design time or at
runtime.
o Properties of the PictureBox Control
1. Image: Gets or sets the image that is displayed in the
control.
2. Initial Image: Gets or sets the image displayed in the
control when the main image is loaded.
3. SizeMode: Determines the size of the image to be
displayed in control. Normal, StrechImage, AutoSize,CenterImage, Zoom
• It represents a Windows progress bar control.
• It is used to provide visual feedback to your users about

the status of some task.


• It shows a bar that fills in from left to right as the

operation.
Properties of the ProgressBar
Control
1. Font: Gets or sets the font of text in the ProgressBar.

2. Value: Gets/ sets the current position of the progress bar.

3. Maximum: maximum value of the range of the control.

4. Minimum: minimum value of the range of the control.

5. MarqueeAnimationSpeed: Gets or sets the time period, in


milliseconds,
o ScrollBar:
 The ScrollBar controls display vertical and horizontal scroll
bars on the form.
 This is used for navigating through large amount of
information.
 There are two types of scroll bar controls:
 HScrollBar: for horizontal scroll bars and VScrollBar: for
vertical scroll bars.
 These are used independently from each other.
1. Value: Gets or sets a numeric value that represents the
current position of the scroll box on the scroll bar control.
2. Maximum: Gets or sets the upper limit of values of the
scrollable range.
3. Minimum: Gets or sets the lower limit of values of the
scrollable range.
4. LargeChange: Gets or sets a value to be added to or
subtracted from the Value property when the scroll box
is moved a large distance.
5. SmallChange: Gets or sets the value to be added to or
subtracted from the Value property when the scroll box is
moved a small distance.
o DateTimePicker:
• The DateTimePicker control allows selecting a date and
time by editing the displayed values in the control.
• If you click the arrow in the DateTimePicker control, it
displays a month calendar, like a combo box control.
• The user can make selection by clicking the required date.
• The new selected value appears in the text box part of the
control.
1. CalendarFont: Gets or sets the font style applied to the
calendar.
2. CalendarForeColor: Gets or sets the foreground color of
the calendar.
3. CalendarMonthBackground: Gets or sets the background
color of the calendar month.
4. CalendarTitleBackColor: Gets or sets the background
color of the calendar title.
5. CalendarTitleForeColor: Gets or sets the foreground
color of the calendar title.
6. Format: Gets or sets the format of the date and time
displayed in the control.
o TreeView:
• It displays a hierarchical collection of labeled items, each
represented by a TreeNode.
o Rich TextBox:
• RichTextBox Control is used to display an image of the file
formats like png, gif, jpeg, bmp, wmf, ico, pcx, tga, tiff.
Images can be loaded either at the design time or at
runtime.
o TIMER:
 Timer Control is used to set time intervals, this control is visible
only at design time and not in the runtime.
o Imagelist:
 ImageList Control is used to store images that can be used with
other controls. This control works fine with the controls that have
the ImageList and ImageIndex property.
o Tooltip:
 Tooltip Control is used to display explanatory text when the
mouse rest on a control or window. This control is helpful in
providing a quick help to users.
End of Chapter 2

By: Ins. Solomon S. 65

You might also like