0% found this document useful (0 votes)
15 views16 pages

Visual Programming 1

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

Visual Programming 1

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

An IDE (Integrated Development Environment) is software that combines commonly used developer

tools into a compact GUI (graphical user interface) application.

It is a combination of tools like a code editor, code compiler, and code debuggIntegrating features
like software editing, building, testing, and packaging in a simple-to-use tool, IDEs help boost
developer productivity.

IDEs are commonly used by programmers and software developers to make their programming
journey smoother with an integrated terminal.

Common Features of an IDE (Integrated Development Environment)

IDEs provide a broad variety of features which typically consist of:

 Editor: Typically a text editor can help you write software code by highlighting syntax with
visual cues, providing language-specific auto-completion, and checking for bugs as you type.

 Compiler: A compiler interprets human-readable code into machine-specific code that can
be executed on different operating systems like Linux, Windows, or Mac OS. Most
IDEs usually come with built-in compilers for the language it supports.

 Debugger: A tool that can assist developers to test and debug their applications and
graphically point out the locations of bugs or errors if any.

 Build-in Terminal: Terminal is a text-based interface that can be used for interacting with the
machine’s operating system. Developers can directly run the scripts or commands within an
IDE with a built-in terminal/console.

 Version Control: Version control helps bring clarity to the development of the
software. Some IDEs also support version control tools like Git, through which a user can
track and manage the changes to the software code.

 Code snippets: IDEs support code snippets that are usually used to accomplish a single task
and can also reduce redundant work to some great extent.

 Extensions and Plugins: Extensions and Plugins are used to extend the functionality of the
IDEs with respect to specific programming languages.

 Code navigation: IDEs come with tools like code folding, class and method navigation, and
refactoring tools that make it simple to go through and analyze code.

Why do Developers Use IDE (Integrated Development Environment)?

By providing a single, unified environment for managing all aspects of the development
process, IDEs can help improve a developer’s productivity, code quality, and overall
development experience.

 Productivity: By combining common activities such as editing code, building executables,


debugging, and testing as part of software/application development, IDEs help by reducing
time and increasing overall productivity.

 Code Quality: IDEs come with built-in tools as a part of a single GUI, through which
developers can execute actions without switching between applications. Furthermore, it can
also help in Syntax highlighting, code refactoring, and code analysis boosting overall code
quality.

 Integrated Environment: IDEs come pre-built with a combination of development tools that
allow developers to start programming new applications quickly. With IDEs, it is no longer
necessary to manually configure and integrate numerous utilities as part of the setup
procedure. Additionally, since every utility is available on the same workbench, developers
don’t have to spend hours learning how to use each one separately.

 Customizability: By incorporating customization options ranging from custom color schemes,


and keyboard shortcuts, to choosing unique layouts, different plugins, and add-ons;
IDEs enable developers to customize their environment to their unique needs and tastes,
improving the comfort and efficiency of the development process.

Types of IDEs

IDEs come in various forms, some are designed to work for a specific language whereas some
are targeted to a particular platform like mobile devices. Hence, it becomes equally
important to choose an IDE best suited to one’s needs.

1. Desktop IDEs

This type includes the IDEs that can be configured locally. They do not need an active
internet connection to build/run programs. Desktop IDEs are highly customizable to suit
developer-specific needs and provide performance irrespective of the internet speed.
Examples: include Microsoft Visual Studio, Eclipse, Netbeans, etc.

2. Cloud IDEs

Cloud IDEs eliminate the overhead of configuring the software locally. They run on remote
servers and can be accessed through desktop browsers. Cloud IDEs provide better
accessibility and platform independence making them accessible through the Internet
Irrespective of the Client Operating System. Cloud IDEs can be used freely or can have pricing
models with respect to the provider. Examples: Include Gitpod, AWS Cloud 9, Replit, etc.

3. Mobile App Development IDEs

These IDEs are specially designed for creating mobile applications. They include features like
Emulator support and integration for developing and testing mobile applications. Mobile
Development IDEs can be in the form of Desktop IDE or Cloud IDE. Examples: Include
Android Studio, Flutlab.io, etc.

4. Database-Specific IDEs
These IDEs (Integrated Development Environments) are specially designed for working with
databases. They include features like query builders and n for developing and testing mobile
applications. Like mobile-development IDEs, Database IDEs can also be in the form of
Desktop IDE or Cloud IDEs. Examples: Include MySQL Workbench, Oracle SQL Developer, etc.

Advantages of using IDE

Some of common advantages of IDEs or Integrated Development Environments are as


follows:

 Project Management: IDEs make viewing the project directory structure much simpler which
breaks down the tedious tasks of working with multiple files. Typically IDEs also include a
number of tools, such as syntax highlighting, code completion, and code folding, which
makes it easier to manage the overall project.

 Saving plenty of time and Effort: IDEs often include a variety of tools that can not only assist
you in organizing your code but also quickly highlight the error in your code. They also
include a flexible combination of tools for compiling, building, testing, and deploying your
code, through which you can automate these tasks eliminating the need to manually run
each task.

 Productivity: IDEs can increase your productivity by providing a centralized location for all of
your development needs, from writing and editing code to debugging and deploying. Some
of the functionality provided by IDEs can also be accomplished with a text editor and
command-line tools, but IDEs usually make the process more convenient and user-friendly.

Disadvantages of using IDE

Some of common disadvantages of IDEs or Integrated Development Environments are as


follows:

 Not beginner Friendly: IDEs are complex tools and generally provide quite an intimidating UI,
which can be a little tough to comprehend for a beginner. Maximizing their benefit generally
needs a dedicated effort.

 Frequent Updates: It’s difficult to keep up with constant updates, such as new samples,
templates, and features.

 Only Assist in writing code: As a tool, IDEs (Integrated Development Environments) are
limited to being an assistant. They can’t write code or automatically fix errors, one still needs
the knowledge to write clean code.

 Cost: Some IDE is Expensive or needs additional costs to unlock some add-ons, which can be
a barrier for small-scale companies or learning Individuals.

Conclusion

Choosing an IDE is usually determined by the type of project you’re working on, as well as
various environmental requirements; offering a variety of features such as code editing,
debugging, and version control that can streamline and increase productivity in the software
development process. Of course, you still must consider your budget and personal
preferences. Overall, the use of IDEs can assist individuals or businesses in improving their
software development process, resulting in shorter time-to-market, cost savings, and higher
software quality.

FORMS:

A Form is used in VB.NET to create a form-based or window-based application. Using the


form, we can build a attractive user interface. It is like a container for holding different
control that allows the user to interact with an application. The controls are an object in a
form such as buttons, Textboxes, Textarea, labels, etc. to perform some action. However, we
can add any control to the runtime by creating an instance of it.

A Form uses a System.Windows.Form namespace, and it has a wide family of controls that
add both forms and functions in a Window-based user interface.

Form Properties

The following are the most important list of properties related to a form. And these
properties can be set or read while the application is being executed.

Properties Description

BackColor It is used to set the background color for the form.

BackgroundImage It is used to set the background image of the form.

Cursor It is used to set the cursor image when it hovers over the form.

AllowDrop Using the AllowDrop control in a form, it allows whether to drag and
drop on the form.

Font It is used to get or set the font used in a form.

Locked It determines whether the form is locked or not.

FormBorderStyle It is used to set or get border style in a form.

Text It is used to set the title for a form window.

MinimizeBox MinimizeBox It is used to display the minimum option on the title bar of
the form.
IsMDIChild It is used to authenticate whether a form is a container of a Multiple
Document Interface (MDI) child form.

Autoscroll It allows whether to enable auto-scrolling in a form.

MaximizeBox It is used to display the maximum option on the title bar of the form.

MaximumSize It is used to set the maximum height and width of the form.

Language It is used to specifies the localized language in a form.

AcceptButton It is used to set the form button if the enter key is pressed.

Top, Left It is used to set the top-left corner coordinates of the form in pixel.

Name It is used to define the name of the form.

MinimumSize It is used to set the minimum height and width of the form.

Enabled It uses the True or False value to enable mouse or keyboard events in
the form.

TopMost It uses a Boolean value that represents whether you want to put the
window form on top of the other form. By default, it is False.

Form Events

The following are the most important list of events related to a form.

Events Description

Activated An activated event is found when the user or program activates the
form.

Click A click event is active when the form is clicked.

Closed A closed event is found before closing the form.


Closing It exists when a form is closing.

DoubleClick DoubleClick
The DoubleClick event is activated when a user double clicks on the
form.

DragDrop A DragDrop event is activated when a drag and drop operation is


performed.

MouseDown A MouseDown event is activated when the mouse pointer is on the


form, and the mouse button is pressed.

GotFocus A GotFocus event is activated when the form control receives a focus.

HelpButtonClicked It is activated when a user clicked on the help button.

KeyDown A KeyDown event is activated when a key is pressed while focussing on


the form.

KeyUp A KeyUp event is activated when a key is released while focusing on the
form.

Load The load event is used to load a form before it is first displayed.

LostFocus It is activated when the form loses focus.

MouseEnter A MouseEnter event is activated when the mouse pointer enters the
form.

MouseHover A MouseHover event is activated when the mouse pointer put on the
form.

MouseLeave A MouseLeave event is activated when the mouse pointer leaves the
form surface.

Shown It is activated whenever the form is displayed for the first time.

Scroll A Scroll event is activated when a form is scrolled through a user or


code.
Resize A Resize event is activated when a form is resized.

Move A Move event is activated when a form is moved.

For creating a Windows Forms application , we need to follow the following steps in
Microsoft Visual Studio.

1. GoTo File Menu.

2. Click on New Project.

3. Click on Windows Forms App or Application

And finally, click on the 'Create' button to create your project, and then, it displays the
following window form with a name Form1.

Now create a simple program of Windows form control

Form1.vb

1. Public Class Form1

2. ' Create nameStr and num variables

3. Dim nameStr As String

4. Dim num As Integer

5. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

6.

7. End Sub

8. ' It is Label1

9. Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

10.

11. End Sub


12. ' It is TextBox1 for inserting the value.

13. Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.Te


xtChanged

14.

15. End Sub

16. ' It is Label2

17. Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

18.

19. End Sub

20.

21. ' It is a Button1 for transferring the control.

22. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

23. nameStr = TextBox1.Text

24. num = TextBox2.Text

25. Label3.Text = "You have entered the Name " & nameStr + " Number " & num

26.

27. End Sub

28.

29. ' It is TextBox2 for inserting the value.

30. Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.Te


xtChanged

31.

32. End Sub

33. ' It is label3

34. Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click

35.

36. End Sub

37. End Class

Output:
Now enter the following details in the form:

After filling all the details, click on the Submit button. After that, it shows the following
Output:

Control Properties

All the Visual Basic Objects can be moved, resized or customized by setting their properties.
A property is a value or characteristic held by a Visual Basic object, such as Caption or Fore
Color.
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.

For example,

Form1.Caption = "Hello"

You can set any of the form properties using Properties Window. Most of the properties can
be set or read during application execution. You can refer to Microsoft documentation for a
complete list of properties associated with different controls and restrictions applied to
them.

Control Methods

A method is a procedure created as a member of a class and they cause an object to do


something. Methods are used to access or manipulate the characteristics of an object or a
variable. There are mainly two categories of methods you will use in your classes −

 If you are using a control such as one of those provided by the Toolbox, you can call any of its
public methods. The requirements of such a method depend on the class being used.

 If none of the existing methods can perform your desired task, you can add a method to a
class.

For example, the MessageBox control has a method named Show, which is called in the code
snippet below −

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Handles Button1.Click

MessageBox.Show("Hello, World")

End Sub

End Class

Control Events

An event is a signal that informs an application that something important has occurred. For
example, when a user clicks a control on a form, the form can raise a Click event and call a
procedure that handles the event. There are various types of events associated with a Form
like click, double click, close, load, resize, etc.
Following is the default structure of a form Load event handler subroutine. You can see this
code by double clicking the code which will give you a complete list of the all events
associated with Form control −

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

'event handler code goes here

End Sub

Here, Handles MyBase.Load indicates that Form1_Load() subroutine handles Load event.
Similar way, you can check stub code for click, double click. If you want to initialize some
variables like properties, etc., then you will keep such code inside Form1_Load() subroutine.
Here, important point to note is the name of the event handler, which is by default
Form1_Load, but you can change this name based on your naming convention you use in
your application programming.

Basic Controls

VB.Net provides a huge variety of controls that help you to create rich user interface.
Functionalities of all these controls are defined in the respective control classes. The control
classes are defined in the System.Windows.Forms namespace.

The following table lists some of the commonly used controls −

Sr.No
Widget & Description
.

Forms
1
The container for all the controls that make up the user interface.

TextBox
2
It represents a Windows text box control.

Label
3
It represents a standard Windows label.

Button
4
It represents a Windows button control.

ListBox
5
It represents a Windows control to display a list of items.

6 ComboBox
It represents a Windows combo box control.

RadioButton
7 It enables the user to select a single option from a group of choices
when paired with other RadioButton controls.

CheckBox
8
It represents a Windows CheckBox.

PictureBox
9
It represents a Windows picture box control for displaying an image.

ProgressBar
10
It represents a Windows progress bar control.

ScrollBar
11
It Implements the basic functionality of a scroll bar control.

DateTimePicker

It represents a Windows control that allows the user to select a date


12 and a time and to display the date and time with a specified format.

TreeViewIt displays a hierarchical collection of labeled items, each


13
represented by a TreeNode.

ListView

It represents a Windows list view control, which displays a collection


14
of items that can be displayed using one of four different views.

EVENTS:

Handling Keyboard Events

Following are the various keyboard events related with a Control class −

 KeyDown − occurs when a key is pressed down and the control has focus

 KeyPress − occurs when a key is pressed and the control has focus
 KeyUp − occurs when a key is released while the control has focus

The event handlers of the KeyDown and KeyUp events get an argument of
type KeyEventArgs. This object has the following properties −

 Alt − it indicates whether the ALT key is pressed

 Control − it indicates whether the CTRL key is pressed

 Handled − it indicates whether the event is handled

 KeyCode − stores the keyboard code for the event

 KeyData − stores the keyboard data for the event

 KeyValue − stores the keyboard value for the event

 Modifiers − it indicates which modifier keys (Ctrl, Shift, and/or Alt) are pressed

 Shift − it indicates if the Shift key is pressed

The event handlers of the KeyDown and KeyUp events get an argument of type
KeyEventArgs. This object has the following properties −

Handled − indicates if the KeyPress event is handled

KeyChar − stores the character corresponding to the key pressed

In Visual Basic , properties are special member variables that provide controlled access to an object’s
data.

Properties allow us to get and set the values of private fields while encapsulating the internal details
of the class.

There are some common types of properties in VB.NET. Properties are essential for encapsulating
data and providing controlled access to class members, promoting good object-oriented
programming practices and data encapsulation.

Some common properties are:-

1. Get Property (Read-Only Property):A get-only property allows us to retrieve the value of a private
field but doesn’t allow us to modify it.

For Example:-

Public ReadOnly Property FirstName As String

Get

Return first_name

End Get

End Property
2. Set Property (Write-Only Property):

A set-only property allows us to set the value of a private field but doesn’t allow us to retrieve it.

For Example:

Public WriteOnly Property Age As Integer

Set(value As Integer)

age = value

End Set

End Property

3. Get-Set Property (Read-Write Property):

A get-set property allows both getting and setting the value of a private field.

For Example:

Public Property LastName As String

Get

Return last_name

End Get

Set(value As String)

Last_Name = value

End Set

End Property

 Auto-Implemented Property:

An auto-implemented property is a shorthand syntax for creating properties when we don’t need
additional logic in the getter or setter. The compiler generates the private field for us.

For Example:

Public Property Str As String

 Read-Only Auto-Implemented Property:

This property is similar to an auto-implemented property, but it’s read-only.

For Example:
Public ReadOnly Property Str As String

 Set-Only Auto-Implemented Property:

This property is similar to an auto-implemented property, but it’s write-only.

For Example:

Public WriteOnly Property IsEnabled As Boolean

 Indexed Property:

An indexed property allows us to access elements of an object as if it were an array.

For Example:

Public Property Items(index As Integer) As String

Get

Return items(index)

End Get

Set(value As String)

items(index) = value

End Set

End Property

 Default Property:

A default property allows us to access an object using an index or key without specifying the
property name.

Example:

Default Public Property Item(index As Integer) As String

Get

Return items(index)

End Get

Set(value As String)

items(index) = value
End Set

End Property

 Shared Property (Shared Member):

A shared property is associated with the class itself rather than with instances of the class.

It’s accessed using the class name.

For Example:

Public Shared Property CompanyName As String

 Custom Properties:

We can create our own custom properties with additional logic in the getter or setter to perform
validation, calculations, or other operations as needed.

You might also like