Pemrograman Visual Minggu II

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Lesson 1: Introduction to VB2019

1.1 Introduction

Microsoft has released Visual Studio 2019 in early 2019. VS 2019 allows you to code in
different programming languages and different platforms, Visual Basic 2019 is one of
them. The other Programming languages are C# C++, F#, JavaScript, Java and Python.
Visual Basic 2019 is the latest version VB.NET programming language released by
Microsoft.

Visual Studio 2019 installer can be downloaded from the link below.

https://visualstudio.microsoft.com/vs/

After downloading and installing VS 2019, you are now ready to launch Visual Studio
2019 and start programming in Visual Basic 2019.

1.2 Visual Studio 2019 Start Page

The VS2019 start page is quite different from VS 2017. When you first launch Visual
Studio 2019, the following start Page appears, as shown in Figure 1.1. You can quickly
launch recently open recently opened projects, clone from GitHub, open a project or
solution, open a local folder or create a new project.

Figure 1.1 Visual Studio 2019 Start Page

Pemrograman Visual – PTIK Unimed | Fahmy S


Let's select Create a new project option and launch the Create a new project page, as
shown in Figure 1.2. We select the Visual Basic language

Figure 1.2 New Project Page


In the Create new project page, we select Windows Forms App(.Net Framework)template
as we want to develop a Windows desktop project, as shown in Figure 1.3

Pemrograman Visual – PTIK Unimed | Fahmy S


Figure 1.3 Select Project Template
Upon clicking the selected project template, the project configuration page appears, as
shown in Figure 1.4. You can configure your project by typing the project name and select
a few other options.

Figure 1.4 Configuring Project

Pemrograman Visual – PTIK Unimed | Fahmy S


1.3 Visual Basic 2019 IDE

Upon clicking the Create button the Visual Basic 2019 IDE, as shown in Figure 1.6.
You can see that the name of the project you entered earlier appears on the top right
corner of the IDE.

Figure 1.5 Visual Basic 2019 IDE

VB2019 IDE comprises a few windows, the Form window, the Solution Explorer window
and the Properties window. It also consists of a toolbox which contains many useful
controls that allow a programmer to develop his or her Visual Basic 2019 program. The
toolbox can be hidden or dragged to the bottom or side of the window.

Now, we shall proceed to show you how to create your first program in Visual Basic
2019. First, change the text of the form to My First vb2019 Program in the properties
window, it will appear as the title of the program. Next, insert a button and change its
text to Display Hidden Message. The design interface is shown in Figure 1.6

Pemrograman Visual – PTIK Unimed | Fahmy S


Figure 1.6 The Design Interface
Click on the Display Hidden Message button to bring up the code window and enter the
following statement between Private Sub and End Sub procedure, as shown in Figure 1.7

Figure 1.7 Visual Basic 2017 Code Window


When you run this program and click on the Display Hidden Message button, you should
get the following popup message box.

Pemrograman Visual – PTIK Unimed | Fahmy S


Figure 1.8 The Message Box
The function MsgBox is a built-in function of Visual Basic 2019 and it will display the text
enclosed within the brackets. Now you have created your first program in Visual Basic
2019, we shall learn more Visual Basic 2019 programming techniques in coming lessons.

Pemrograman Visual – PTIK Unimed | Fahmy S


Lesson 2: Designing the User Interface(UI)

Prior to creating a Visual Basic 2019 project, you need to conceive an idea of what kind
of project you intend to develop. Maybe you want to develop a desktop game, a
multimedia app, a financial app, a database management app and so forth. Once you
have decided on the app you wish to develop, the first step is to design the User
Interface(UI). To design the UI, we suggest you sketch it first on a piece of paper before
working on it in the VB2019 IDE. After completed and refined your design on paper, then
only you start designing the app on the VB2019 IDE.
To start designing your VB2019 app, start VS 2019 and launch the VB2019 project. In the
VB209 IDE, you should customize your default form first by using the properties windows.
Properties that you can set for the default form are its size, background color, foreground
color, font size, title and more. After customizing the default form, you can start adding
various controls from the toolbox to the default form and then customize their properties.
After designing the app UI, you can then write code for all the controls. We will learn more
about coding in the coming lessons.

2.1 Customizing the Default-Form

When you start a new Visual Basic 2019 project, the IDE will display the default form
along with the Solution Explorer window and the Properties window on the far right, as
shown in Figure 2.1.

Figure 2.1: Initial Visual Basic 2019 IDE

The properties window comprises an object drop-down list, a list of properties and the
bottom section that shows a description of the selected property. As the only object on
the IDE is the default form by the name of Form1, the properties window displays all

Pemrograman Visual – PTIK Unimed | Fahmy S


properties related to Form1 and their corresponding attributes or values, as shown in
Figure 2.2. You can change the name of the Form, the title of the Form, the background
color, the foreground color, the size and more. Properties can be changed by typing a
value or select a value from a drop-down list. For the color setting, you just need to
select a color rectangle or from a color palette.

Figure 2.2: The Properties window


Now let us specify the following properties for Form1.

Property Value
Name MyForm
Text My First vb2019 Program
BackColor 255, 51, 153
ForeColor White
MaximizeBox False
Font Arial, 9.75pt
* The value for Backcolor (background color) 255, 51, 153 is the RGB color code for some
kind of pink. The Foreground color will be the color of the text on a Label control places
on the default Form. Instead of typing the RGB value, you can also select the color from
the color drop-down list that comprises three tabs, Custom, Web, and System. Clicking
on the drop-down arrow will bring out a color palette or a list of color rectangles where
you can select a color, as shown in the figures below:

Pemrograman Visual – PTIK Unimed | Fahmy S


The runtime UI is shown in Figure 2.6. Notice that the title of the form has been changed
from Form1 to My First VB2019 Project, the background color is pink, the Label is white
and the window cannot be maximized.

Figure 2.6: The Runtime UI

2.2 Changing the Properties of the Default-Form at Run-Time

You can also change the properties of the form at run-time by writing the relevant
codes. The default form is an object and an instant of the form can be denoted by the
name Me. The property of the object can be defined by specifying the object’s name
follows by a dot or period:

Pemrograman Visual – PTIK Unimed | Fahmy S


ObjectName.property

For example, we can set the background color of the form to cyan using the following
code

Me.BackColor=Color.Cyan
Example 2.1

To achieve the same interface as in Figure 2.6, type in the following code by clicking the
form to enter the code window:

Public Class Form1


Private Sub Form1_Load(ByVal sender As Object, ByVal e As
EventArgs)Handles MyBase.Load
Me.Text = “My First vb2017 Program”
Me.BackColor = Color.Pink
Me.MaximizeBox=False
Me.MinimizeBox = True
End Sub
End Class
Example 2.2

You can also specify the size, the opacity and the position of the default form using the
code, as follows:

Private Sub Form1_Load(sender As Object, e As EventArgs Handles


MyBase.Load
Me.Text = “My First VB2019 Project”
Me.BackColor =Color.Beige
Me.MaximizeBox = False
Me.MinimizeBox = True
'Specifying the form size to 400pixel x 400pixel
Me.Size = New Size(400, 400)
'To set the form opacity at 85%
Me.Opacity = 0.85
'To position the form at the center of the screen
Me.CenterToParent()
End Sub

The runtime interface is shown in Figure 2.7

Pemrograman Visual – PTIK Unimed | Fahmy S


Figure 2.7
The Form is positioned to the center of the screen and the faint lines appear behind the
Form as its opacity was set to 85%.

Pemrograman Visual – PTIK Unimed | Fahmy S

You might also like