SlideShare a Scribd company logo
Renas R. Rekany Object-Oriented-Programming L1A
1
Object-Oriented-Programming
Stage: Second Computer
Science
Department
Computer &
I.T Faculty
Units
8
Hours
Theoretical 2,
Practical 2
Tutorial 2
OOP
Lec: Renas R. Rekany
2015/2016
Renas R. Rekany Object-Oriented-Programming L1A
2
History of programming languages
1- Microsoft .Net Framework
.NET Framework (pronounced dot net) is a software framework developed by Microsoft that
runs primarily on Microsoft Windows. It includes a large class library known as Framework
Class Library (FCL) and provides language interoperability(each language can use code written
in other languages) across several programming languages. Programs written for .NET
Framework execute in a software environment (as contrasted to hardware environment), known
as Common Language Runtime (CLR), an application virtual machine that provides services
such as security, memory management, and exception handling. FCL and CLR together
constitute .NET Framework.
FCL provides user interface, data access, database connectivity, cryptography, web
application development, numeric algorithms, and network communications.
Programmers produce software by combining their own source code with .NET
Framework and other libraries. .NET Framework is intended to be used by most new
applications created for the Windows platform. Microsoft also produces an integrated
development environment largely for .NET software called Visual Studio.
2-Different DOTNET Types of Applications
There are three main types of application that can be written in C#:
1. Winforms : Windows applications have the familiar graphical user interface
of Windows with controls such as buttons and list boxes for input.
2. Console: Console applications use standard command-line input and output
for input and output instead of a form.
[[[[
Renas R. Rekany Object-Oriented-Programming L1A
3
3. Web Sites.
3- Starting Visual Studio (2008/2015)
-Double click on Microsoft Visual Studio (2008/2015) icon on desktop.
OR
-Open the Start menu, select All Programs, and then select Microsoft Visual Studio 2008/2015.
Renas R. Rekany Object-Oriented-Programming L1A
4
Renas R. Rekany Object-Oriented-Programming L1A
5
4- Create First Winforms application
Step 1: Start Visual Studio
Open the Microsoft Visual Studio 2008/2015.
Step 2: Create a new project
Go to File -> New Project, And then New Project Dialog Appears.
In the New Project Window, Select Visual C# as Project type and Windows Forms
Applications as the template. Give Name and Location to your project and finally
click OK button to create our first C# project.
Renas R. Rekany Object-Oriented-Programming L1A
6
Step 3: Design the user interface.
When the project is created, you will see the designer view of your interface as
follows.
Form Designer View
Renas R. Rekany Object-Oriented-Programming L1A
7
In this designer view of the form (Form1.cs [Design]), you can design the user
interface of the single form. To do that, we use the 'Toolbox' which contains the
items that you can add to your form. Toolbox is placed on the left side of your
visual studio. If it is not visible go to View -> Toolbox to show the Toolbox.
Toolbox
It contains Labels, Buttons, Check Boxes, Combo Boxes and etc. This can be used
to design your interface. To add elements from the Toolbox to your form double
click the item or drag the item to your form.
Now add a Button Control to your form by simple dragging a Button control into
the form designer view. Finally it looks like below.
Now our form contains two elements. Those are form and the button control.
These elements have properties such as name, text, background color, fore color,
Renas R. Rekany Object-Oriented-Programming L1A
8
etc.... To see properties for a control, select the control and all the properties are
displayed in the Properties Window which appears on the right side of your visual
studio. If it is not visible, Go to View -> Properties Window.
Select the button and view properties as follows.
Now set the text to 'Show' for the button.
Renas R. Rekany Object-Oriented-Programming L1A
9
Step 4: Writing the code
Double click on buttun1 to write the code
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World!");
}
Step 5: Compile the code
To compile the code Go to Build -> Build HelloWorld
Step 6: Running the application
To run/execute the program press F5.
Running Application.
Renas R. Rekany Object-Oriented-Programming L1A
10
6- Create First Web application
Building Your First Web Application Project
Creating a New Project
Select File->New Project within the Visual Studio 2005 IDE. This will bring up the New Project
dialog. Click on the “Visual C#” node in the tree-view on the left hand side of the dialog box and
choose the "ASP.NET Web Application" icon:
Visual Studio will then create and open a new web project within the solution explorer. By
default it will have a single page (Default.aspx), an AssemblyInfo.cs file, as well as a web.config
file. All project file-meta-data is stored within a MSBuild based project file.
Renas R. Rekany Object-Oriented-Programming L1A
11
Opening and Editing the Page
Double click on the Default.aspx page in the solution explorer to open and edit the page. You
can do this using either the HTML source editor or the design-view. Add a "Hello world" header
to the page, along with a calendar server control and a label control (we'll use these in a later
tutorial):
Renas R. Rekany Object-Oriented-Programming L1A
12
Build and Run the Project
Hit F5 to build and run the project in debug mode. By default, ASP.NET Web Application
projects are configured to use the built-in VS web-server when run. The default project
templates will run on a random port as a root site (for example: http://localhost:12345/):
Renas R. Rekany Object-Oriented-Programming L1A
13
You can end the debug session by closing the browser window, or by choosing the Debug->Stop
Debugging (Shift-F5) menu item.
Customizing Project Properties
ASP.NET Web Application Projects share the same configuration settings and behaviors as
standard VS 2005 class library projects. You access these configuration settings by right-clicking
on the project node within the Solution Explorer in VS 2005 and selecting the "Properties"
context-menu item. This will then bring up the project properties configuration editor. You can
use this to change the name of the generated assembly, the build compilation settings of the
project, its references, its resource string values, code-signing settings, etc:
Renas R. Rekany Object-Oriented-Programming L1A
14
ASP.NET Web Application Projects also add a new tab called "Web" to the project properties
list. Developers use this tab to configure how a web project is run and debugged. By default,
ASP.NET Web Application Projects are configured to launch and run using the built-in VS Web
Server (aka Cassini) on a random HTTP port on the machine.
This port number can be changed if this port is already in use, or if you want to specifically test
and run using a different number:
Renas R. Rekany Object-Oriented-Programming L1A
15
Alternatively, Visual Studio can connect and debug IIS when running the web application. To
use IIS instead, select the "Use IIS Web Server" option and enter the url of the application to
launch, connect-to, and use when F5 or Control-F5 is selected:
Renas R. Rekany Object-Oriented-Programming L1A
16
Then configure the url to this application in the above property page for the web project. When
you hit F5 in the project, Visual Studio will then launch a browser to that web application and
automatically attach a debugger to the web-server process to enable you to debug it.
Note that ASP.NET Web Application Projects can also create the IIS vroot and configure the
application for you. To do this click the "Create Virtual Directory" button.

More Related Content

C# p1

  • 1. Renas R. Rekany Object-Oriented-Programming L1A 1 Object-Oriented-Programming Stage: Second Computer Science Department Computer & I.T Faculty Units 8 Hours Theoretical 2, Practical 2 Tutorial 2 OOP Lec: Renas R. Rekany 2015/2016
  • 2. Renas R. Rekany Object-Oriented-Programming L1A 2 History of programming languages 1- Microsoft .Net Framework .NET Framework (pronounced dot net) is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large class library known as Framework Class Library (FCL) and provides language interoperability(each language can use code written in other languages) across several programming languages. Programs written for .NET Framework execute in a software environment (as contrasted to hardware environment), known as Common Language Runtime (CLR), an application virtual machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute .NET Framework. FCL provides user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and network communications. Programmers produce software by combining their own source code with .NET Framework and other libraries. .NET Framework is intended to be used by most new applications created for the Windows platform. Microsoft also produces an integrated development environment largely for .NET software called Visual Studio. 2-Different DOTNET Types of Applications There are three main types of application that can be written in C#: 1. Winforms : Windows applications have the familiar graphical user interface of Windows with controls such as buttons and list boxes for input. 2. Console: Console applications use standard command-line input and output for input and output instead of a form. [[[[
  • 3. Renas R. Rekany Object-Oriented-Programming L1A 3 3. Web Sites. 3- Starting Visual Studio (2008/2015) -Double click on Microsoft Visual Studio (2008/2015) icon on desktop. OR -Open the Start menu, select All Programs, and then select Microsoft Visual Studio 2008/2015.
  • 4. Renas R. Rekany Object-Oriented-Programming L1A 4
  • 5. Renas R. Rekany Object-Oriented-Programming L1A 5 4- Create First Winforms application Step 1: Start Visual Studio Open the Microsoft Visual Studio 2008/2015. Step 2: Create a new project Go to File -> New Project, And then New Project Dialog Appears. In the New Project Window, Select Visual C# as Project type and Windows Forms Applications as the template. Give Name and Location to your project and finally click OK button to create our first C# project.
  • 6. Renas R. Rekany Object-Oriented-Programming L1A 6 Step 3: Design the user interface. When the project is created, you will see the designer view of your interface as follows. Form Designer View
  • 7. Renas R. Rekany Object-Oriented-Programming L1A 7 In this designer view of the form (Form1.cs [Design]), you can design the user interface of the single form. To do that, we use the 'Toolbox' which contains the items that you can add to your form. Toolbox is placed on the left side of your visual studio. If it is not visible go to View -> Toolbox to show the Toolbox. Toolbox It contains Labels, Buttons, Check Boxes, Combo Boxes and etc. This can be used to design your interface. To add elements from the Toolbox to your form double click the item or drag the item to your form. Now add a Button Control to your form by simple dragging a Button control into the form designer view. Finally it looks like below. Now our form contains two elements. Those are form and the button control. These elements have properties such as name, text, background color, fore color,
  • 8. Renas R. Rekany Object-Oriented-Programming L1A 8 etc.... To see properties for a control, select the control and all the properties are displayed in the Properties Window which appears on the right side of your visual studio. If it is not visible, Go to View -> Properties Window. Select the button and view properties as follows. Now set the text to 'Show' for the button.
  • 9. Renas R. Rekany Object-Oriented-Programming L1A 9 Step 4: Writing the code Double click on buttun1 to write the code private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Hello World!"); } Step 5: Compile the code To compile the code Go to Build -> Build HelloWorld Step 6: Running the application To run/execute the program press F5. Running Application.
  • 10. Renas R. Rekany Object-Oriented-Programming L1A 10 6- Create First Web application Building Your First Web Application Project Creating a New Project Select File->New Project within the Visual Studio 2005 IDE. This will bring up the New Project dialog. Click on the “Visual C#” node in the tree-view on the left hand side of the dialog box and choose the "ASP.NET Web Application" icon: Visual Studio will then create and open a new web project within the solution explorer. By default it will have a single page (Default.aspx), an AssemblyInfo.cs file, as well as a web.config file. All project file-meta-data is stored within a MSBuild based project file.
  • 11. Renas R. Rekany Object-Oriented-Programming L1A 11 Opening and Editing the Page Double click on the Default.aspx page in the solution explorer to open and edit the page. You can do this using either the HTML source editor or the design-view. Add a "Hello world" header to the page, along with a calendar server control and a label control (we'll use these in a later tutorial):
  • 12. Renas R. Rekany Object-Oriented-Programming L1A 12 Build and Run the Project Hit F5 to build and run the project in debug mode. By default, ASP.NET Web Application projects are configured to use the built-in VS web-server when run. The default project templates will run on a random port as a root site (for example: http://localhost:12345/):
  • 13. Renas R. Rekany Object-Oriented-Programming L1A 13 You can end the debug session by closing the browser window, or by choosing the Debug->Stop Debugging (Shift-F5) menu item. Customizing Project Properties ASP.NET Web Application Projects share the same configuration settings and behaviors as standard VS 2005 class library projects. You access these configuration settings by right-clicking on the project node within the Solution Explorer in VS 2005 and selecting the "Properties" context-menu item. This will then bring up the project properties configuration editor. You can use this to change the name of the generated assembly, the build compilation settings of the project, its references, its resource string values, code-signing settings, etc:
  • 14. Renas R. Rekany Object-Oriented-Programming L1A 14 ASP.NET Web Application Projects also add a new tab called "Web" to the project properties list. Developers use this tab to configure how a web project is run and debugged. By default, ASP.NET Web Application Projects are configured to launch and run using the built-in VS Web Server (aka Cassini) on a random HTTP port on the machine. This port number can be changed if this port is already in use, or if you want to specifically test and run using a different number:
  • 15. Renas R. Rekany Object-Oriented-Programming L1A 15 Alternatively, Visual Studio can connect and debug IIS when running the web application. To use IIS instead, select the "Use IIS Web Server" option and enter the url of the application to launch, connect-to, and use when F5 or Control-F5 is selected:
  • 16. Renas R. Rekany Object-Oriented-Programming L1A 16 Then configure the url to this application in the above property page for the web project. When you hit F5 in the project, Visual Studio will then launch a browser to that web application and automatically attach a debugger to the web-server process to enable you to debug it. Note that ASP.NET Web Application Projects can also create the IIS vroot and configure the application for you. To do this click the "Create Virtual Directory" button.