You are on page 1of 21

1

UNIVERSIDAD NACIONAL DE CHIMBORAZO

ENGINEERING FACULTY

SYSTEMS AND COMPUTER SCHOOL

FIFTH SEMESTER-A

TOPIC: Creation of a basic Windows Forms on the IDE Visual Studio 2019 by

using programing language C#.

MEMBERS:

René D. Carranza Guijarro.

Sahiry X. Zhuño Quizhpe

ACADEMIC PERIOD

MARCH – AUGUST 2019


2

CONTENTS
TABLES. ....................................................................................................................... 3
FIGURES. ...................................................................................................................... 3
INTRODUCTION: ........................................................................................................ 4
1. CHAPTER I. ........................................................................................................ 4
1.1. OBJECTIVES. ............................................................................................. 4
1.1.1. GENERAL OBJETIVE: ........................................................................ 4
1.1.2. SPECIFIC OBJETIVES: ....................................................................... 4
2. CHAPTER II. ....................................................................................................... 4
2.1. VISUAL STUDIO INTERFACE .................................................................. 6
2.2. Create a new project....................................................................................... 9
2.3. Add tools to the form ................................................................................... 11
2.4. CREATION OF A PROGRAM ON WINDOWS FORM. .......................... 12
2.4.1. CREATE A PROJECT: ....................................................................... 12
2.4.2. CONFIGURE THE FORM.................................................................. 14
2.4.3. PUT THE CONTROLS ON THE FORM. .......................................... 16
2.4.4. PROGRAM BUTTONS. ..................................................................... 19
2.4.5. RUN THE PROGRAM........................................................................ 21
3. CHAPTER III. ................................................................................................... 21
3.1. CONCLUSIONS.......................................................................................... 21
3

TABLES.
Table 1: Properties of the other controls. ..................................................................... 18

FIGURES.
Figure 1: Principal Window of Visual Studio.............................................................. 12
Figure 2: Choose the Project. ....................................................................................... 13
Figure 3: Name and path of Project. ............................................................................ 14
Figure 4: Project. .......................................................................................................... 14
Figure 5: Change the size of form................................................................................ 15
Figure 6: Change the start position of the form. .......................................................... 15
Figure 7: Name of Form. ............................................................................................. 16
Figure 8: Drag the components to the form. ................................................................ 17
Figure 9: Control on the form. ..................................................................................... 17
Figure 10: Change the property “Name” of “button1”. ............................................... 18
Figure 11: Change the property “Text” of the “button1”. ........................................... 18
Figure 12: Change “ReadOnly” property. ................................................................... 19
Figure 13: Result. ......................................................................................................... 19
Figure 14: Code for summing two numbers. ............................................................... 20
Figure 15: Code for subtracting two numbers. ............................................................ 20
Figure 16: Code for multiplying two numbers. ........................................................... 20
Figure 17: Code for dividing two numbers. ................................................................. 20
Figure 18: Code for initialize the components. ............................................................ 21
Figure 19: The program is ready. ................................................................................. 21
4

INTRODUCTION:
In this document we try to explain the object-oriented programming, detailing what a
class is, what a class attribute is, what class methods are and finally what an object is.
Later we explained how to use the Visual Studio interface and the realization of a
program through the "Windows Forms" project.

1. CHAPTER I.
1.1. OBJECTIVES.
1.1.1. GENERAL OBJETIVE:
To create a basic Windows Forms on the IDE Visual Studio 2019 by using programing
language C#.
1.1.2. SPECIFIC OBJETIVES:
 To know the basis of object-oriented programming and its characteristics
 Describe the interface, the main tools and the most used properties
 To explain the basic use of the project Windows Form for creation of programs.
2. CHAPTER II.
2.1. OBJECT-ORIENTED PROGRAMMING
 It is a programming paradigm that uses objects and attributes to design
applications and computer programs.
 It's a special way of programming, closer to how we would express things in
real life

2.1.1. WHAT IS AN OBJECT


It is the representation of a real concept within our program.
It contains a state, behavior and identity
Therefore, every object in the real world has 2 components:
 Characteristics (attributes)
 Behavior (methods).

Example:
We have a bicycle
5

Object. My bike
Attributes: they allow to express qualities of the object or characteristics that it
possesses
 Color is black:
 Speed is 0 Km:
 Number of wheels is 2:
Methods: actions performed by the object
 Move along
 Shift gears
 Brake
2.1.2. WHAT IS A CLASS?
It is the description of a set of objects; consists of methods and attributes
(data) that summarize common characteristics of the objects
When we program an object and define its characteristics and functionalities,
what we are really doing is programming a class.
2.1.3. Attributes
They are the characteristics of the objects. When we define a property we
usually specify its name and its type
2.1.4. Methods
Are those that describe the behavior of an object
2.1.5. Heritage.
It is a property that allows objects to be created from existing ones, obtaining
characteristics (methods and attributes) similar to those already existing.
Example:
Class: Bicycle

Attributes:
 Color is black:
 Speed is 0 Km:
 No. of wheels is 2
6

Object 1: My Bicycle

 Color is orange:
 Speed is 0 Km:
 No. of wheels is 2:
Object 2: Your Bike

 Color is red:
 Speed is 1 Km:
 No. of wheels is 2:

The methods are the same


 Advance
 Change of March
 Stop

2.2. VISUAL STUDIO INTERFACE


Visual studio has several tools that help make the work easier, each one of these tools
will be identified in the visual studio interface.
In the main window of Visual Studio we can find the title bar, menu bar, toolbox,
form window. Each component is described below.
7

Figure 1: Visual studio interface

1. Toolbox
The toolbox is an important element in the IDE, because that is where the controls that
we will use in our projects are. The toolbox contains more than 130 controls to use in
our programming tasks.
8

Figure 2: Toolbox

2. Menu bar
 The menu bar is frequently used in the development of our applications, the
file menu contains important submenus.
For example if you open File menu you will find, open a project, create a
project, save, configuration, exit
 In the Edit menu, the most important options are: Cut, Copy, Paste, and
Delete.
 In the View menu you will find the option to see the code, the designer mode
and something important is that if a window is not displayed, for example the
toolbox, in the View menu we can enable
 From the project menu and its items, you can add forms to your projects, using
"Add Windows Forms" and other elements you need. You can also here,
change the configuration of the projects
9

 The debug menu is very important because it allows you to test the projects
you are developing and the changes that you are making.
 In the Tools menu we find an important item that is useful to work with
databases (Connect with database) because it is useful to connect databases
with Visual Studio applications
 In the window menu there is a very important element like Reset window
design that allows you to recover the integrated development environment to
its default configuration.

Figure 3: Menu bar

3. Homepage
On the homepage, we find the options to open a project, create a project, and show
recently created projects.

Figure 4: Homepage

2.3. Create a new project


To create a new project, follow the next steps
1. Open Visual Studio.
10

2. Open the file menu, select "new project"

Figure 5: New project

3. Select c#, then select “Application of Windows Forms”, name for the project and
finally click on next.

Figure 6: new project window

4. In the center of the screen our created project is shown


11

Figure 7: Project

2.4. Add tools to the form


1. To add a tool to the form we must first select and then drag to the form. For
example, select a label and drag to the form.

Drag to the form

Select the label tool

Figure 8: Tools

2. Properties
12

For example in the text option, we enter the text to show. We have options to
change text color and size

Our text

Write

Figure 9: Properties

2.5. CREATION OF A PROGRAM ON WINDOWS FORM.


In this example, we are going to create a calculator on windows form through Visual
Studio, so we need to follow the next steps:
2.5.1. CREATE A PROJECT:
1. Open Visual Studio.
2. Select create a project.

Figure 1: Principal Window of Visual Studio.


13

3. Then you need to write in the search bar “Windows Form”, then select
“Application of Windows Forms” and finally click on next.

Figure 2: Choose the Project.

4. Now, you can give the project a name, in the example my project will be called
“MY_FIRST_PROJECT”, then you need to set where it will be saved and click
on create.
14

Figure 3: Name and path of Project.

Figure 4: Project.

Visual Studio creates automatically a form, where you can put controls and set up the
program.
2.5.2. CONFIGURE THE FORM.
15

1. Change size of the form.


For changing size of the form, you need to put the cursor on the sides of the form and
with the sustained click you drag the mouse.

Figure 5: Change the size of form.

2. Change the start location of the form.


You need to go properties panel and look for “StartPosition”, then click on there, and
select the “CenterScreen” option.
With that the form always will open in the center of the screen.

Figure 6: Change the start position of the form.

3. Change the name of the form.


16

In properties panel look for the property “Text” and write here the name of the form, in
my example I will put it “CALCULATOR”.

Figure 7: Name of Form.

2.5.3. PUT THE CONTROLS ON THE FORM.


For this example, we are going to do a calculator, so we need four buttons (Addition,
Subtraction, Multiplication and Division) and three “TextBox”.
When the user clicks on some button, the program will do some operation with the
values of the “TextBox”.
1. Go to the controls panel and you write in the search bar “Button”, then select
the component “Button” y you drag to space work.
17

Figure 8: Drag the components to the form.

For the other buttons, you need to repeat the same action and for text box, too.
In addition, we are going to put an extra button for cleaning the text boxes and we put
a component called “Label” for the titles of the text boxes.
This have to be the result.

Figure 9: Control on the form.


18

2. Properties “Name” and “Text” of the controls.


The property “Name” show the name of component on the program, while the property
“Text” change the word “button1” to that you had written in this property.
First, we are going to change the properties “Name” and “Text” of the “button1”.
Select the “button1”, then you need to go to the properties panel and look for the
property “Name” and you change it to “Addition”.

Figure 10: Change the property “Name” of “button1”.

Now select the “button1” again with the mouse and look for the property “Text” in the
panel and change to “+”.

Figure 11: Change the property “Text” of the “button1”.

Change these properties for the other controls like the next table show you.

Table 1: Properties of the other controls.


19

CONTROL NAME TEXT


Button1 Addition +
Button2 Subtraction -
Button3 Multiplication X
Button4 Division /
Button5 Clean CLEAN
Textbox1 Number1
Textbox2 Numer2
Textbox3 Result
Label1 Number 1:
Label2 Number 2:
Label3 Result:

Finally we are going to change the property of the “textbox3 (Result)” called
“ReadOnly” to true. This property avoids that the user can write in this text box.

Figure 12: Change “ReadOnly” property.

Figure 13: Result.

2.5.4. PROGRAM BUTTONS.


20

For program the buttons of our Project, we are going to double click on them and we
write the codes that we detail below.
1. Addition.

Figure 14: Code for summing two numbers.

2. Subtraction.

Figure 15: Code for subtracting two numbers.

3. Multiplication.

Figure 16: Code for multiplying two numbers.

4. Division.

Figure 17: Code for dividing two numbers.

5. Clean.
21

Figure 18: Code for initialize the components.

2.5.5. RUN THE PROGRAM.

Figure 19: The program is ready.

3. CHAPTER III.
3.1. CONCLUSIONS.
 Object-oriented programming (OOP) is a programming paradigm based on the
concept of "objects"and code, a feature of objects is an object's procedures that
can access and often modify the data fields of the object.
 Was explained the basis use of the project windows form for creation of
programs, where we created a calculator with two numbers, by using buttons
text box, label, “Name” property, “Text” property and some programing.
 Visual studio offers great ease of use, has a simple interface very easy to use
and many tools that make the work easier. Was explained how to create a
project, the tools we can use in the project and how to change the properties.

You might also like