Professional Documents
Culture Documents
Programming in VB NET
Programming in VB NET
NET
Rohit Birla
RohitKumarBirla@gmail.com
RohitBirla_rb@yahoo.com
Rohit Birla
RohitKumarBirla@gmail.com
RohitBirla_rb@yahoo.com
Preface
It gives me great pleasure in presenting this book. Programming in VB.NET is
written with several goals in mind. It is designed to cover all essential and basic
information you will need to start your programming in VB.NET.
I hope this book will help you to start your programming in .NET.
In spite of all efforts some errors might be there. I shall be grateful to the
readers if the same are brought to my notice. Suggestions and comments for
further improvements of the book will be gratefully acknowledged.
June 29, 2010
Rohit Birla
RohitKumarBirla@gmail.com
RohitBirla_rb@yahoo.com
Dedicate to
The person who had given me the name `Rohit`
Contents:
PREFACE ................................................................................................................................................................ 3
ABOUT THE AUTHOR: ............................................................................................................................................ 4
ABOUT THE BOOK: ................................................................................................................................................. 6
CONTENTS: ............................................................................................................................................................ 7
.NET HISTORY ...................................................................................................................................................... 14
.NET HISTORY .............................................................................................................................................................14
APPLICATIONS THAT CAN BE DEVELOPED UNDER .NET ........................................................................................ 14
VISUAL STUDIO INTEGRATED DEVELOPED ENVIRONMENT .................................................................................. 14
WHY TO USE VS IDE ....................................................................................................................................................14
TYPES OF APPLICATIONS ...................................................................................................................................... 15
SINGLE TIER APPLICATIONS: ............................................................................................................................................15
TWO TIER APPLICATIONS: ..............................................................................................................................................15
FAT CLIENT: .......................................................................................................................................................15
FAT SERVER: .......................................................................................................................................................15
DIVIDING BUSINESS SERVICES BETWEEN USER AND DATA SERVICES: ................................................................................15
LIMITATIONS OF TWO TIER APPLICATIONS: .........................................................................................................................16
THREE TIER APPLICATIONS:.............................................................................................................................................16
N TIER APPLICATIONS: ................................................................................................................................................ 16
WHY TO USE .NET ................................................................................................................................................ 17
ADVANTAGES OF USING .NET FRAMEWORK ......................................................................................................................17
.NET ARCHITECTURE ............................................................................................................................................ 17
LAYER 1: ....................................................................................................................................................................18
LAYER 2: ....................................................................................................................................................................18
LAYER 3: ....................................................................................................................................................................18
MANAGE CODE ...........................................................................................................................................................18
GARBAGE COLLECTION PROCESS .....................................................................................................................................18
NAMESPACES: .............................................................................................................................................................19
ASSEMBLY: .................................................................................................................................................................19
MANAGE CODE EXECUTION PROCESS .................................................................................................................. 20
EXPLANATION: .............................................................................................................................................................20
FIRST VB.NET PROGRAM...................................................................................................................................... 21
HELLO WORLD AGAIN!!! ...............................................................................................................................................21
SECOND VB.NET PROGRAM ................................................................................................................................. 23
THIRD PROGRAM (USING STRUCTURES) .............................................................................................................. 24
INHERITANCE ....................................................................................................................................................... 35
CODE REUSABILITY ........................................................................................................................................................35
TYPES OF INHERITANCE ..................................................................................................................................................35
VARIABLE SCOPE ..........................................................................................................................................................35
HOW TO INHERIT..........................................................................................................................................................35
RUN TIME POLYMORPHISM ................................................................................................................................. 37
OBJECT SLICING, RUN TIME BINDING, LATE BINDING...........................................................................................................37
EXAMPLE ....................................................................................................................................................................37
MAIN1 ......................................................................................................................................................................37
MAIN2 ......................................................................................................................................................................38
RUN TIME POLYMORPHISM MAIN3 .................................................................................................................................38
Assignment: ...................................................................................................................................................................... 39
10
TIMER .................................................................................................................................................................. 83
PROPERTY WINDOW:....................................................................................................................................................83
EXAMPLE: ...................................................................................................................................................................83
LINKLABEL ............................................................................................................................................................ 84
EXAMPLE: ...................................................................................................................................................................84
PROGRESSBAR ..................................................................................................................................................... 85
EXAMPLE: ...................................................................................................................................................................85
WEBBROWSER ..................................................................................................................................................... 86
EXAMPLE: ...................................................................................................................................................................86
MASKEDTEXTBOX ................................................................................................................................................ 87
RADIOBUTTON .................................................................................................................................................... 88
EXAMPLE: ...................................................................................................................................................................88
A BIG CONFUSION!!! ............................................................................................................................................ 89
CONFUSION SOLVED ............................................................................................................................................ 90
COMBOBOX ......................................................................................................................................................... 91
EXAMPLE: ...................................................................................................................................................................91
STILL, CONFUSION!!! ............................................................................................................................................ 92
11
12
13
.NET History
.NET History
.NET 1.0
.NET 1.1
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
2002
2003
2005
2007
2008
2010
.NET 2010 is the latest version of .NET. We will be using the same in our programs.
Console Applications
Windows Applications
Web Applications
Component Libraries
Windows Custom Control
Web Custom Control
Web Service
Windows Service
And lots more
Types of Applications
Single tier Applications:
A single executable file handles all functions relating to user, business and data service layer.
Such an application also called monolithic application. Ex: Very early COBOL applications, console
applications (DOS mode applications), In Dbase and FoxPro; user interface is with Database.
Fat Client:
Business services layer combine with user services layer. Client executes presentation
logic and enforces business rules. Server stores data and process transactions. Fat client model is use
when server is overloaded with transaction processing activities and not available to process business
logic.
Fat Server:
Business services layer combine with data services layer. As business services stored on
server most of processing take place on server.
15
n Tier Applications:
An n tier architecture/ application use multiple server handling business services. This
architecture provides various advantages over other architectures. Ex: extensibility, maintainability and
scalability. One of most important requirements of such application is the ability to interchange info
across platform and to benefit from the functionality provided by other application. In other words,
there should be increased interoperability and integration between various applications. A website may
register its consumers and provides services to them; however it may not be capable of interacting with
other websites that providing complementary services to customers. For performing such tasks;
applications needs to provide cross platform application integration.
16
.NET Architecture
17
Layer 1:
Layer 1 Consists of web forms, windows forms and console applications that constitute to the
presentation layer of an application. Web forms are used in web applications where as windows forms
are used in windows based applications for providing interacting user interface. In addition, you can
create character based console application that can be executed from command line.
Layer 2:
One of the most important features of .NET Framework class library is that it can be used in a
consistent manner across multiple languages. This means, you can use same set of classes for
performing a specific task in VB.NET as well as in C++.NET. The .NET Framework class libraries contain
namespaces which are contained within assemblies.
Layer 3:
The common language runtime provides functionality such as exception handling, security,
debugging, and version control to any language that target it. This means that common language
runtime can host a variety of languages and offer a common set of tools across these languages ensuring
interoperability between codes. Ex: the runtime can execute programs written in any language such as
VB.NET, C#.NET and C++.NET with manage extension.
Manage Code
-
Code that is developed with a language compiler that target CLR called manage code
Code that is developed without considering the conventions and requirements of runtime
called unmanaged code. Unmanaged code runs in CLR with limited debugging and without
garbage collection process.
18
Namespaces:
Namespaces helps you to create logical groups of related classes and interfaces that can be used
by any language targeting .NET framework. Namespaces allow you to organize your classes so that they
can be easily accessed in other application. Namespaces can also be used to avoid any naming conflicts
between classes that have same name. Ex: you can use two classes with same name in an application
provided they belong to different namespaces. You can access classes belonging to a namespace by
simply using namespace name followed by dot (.) and then class name.
Ex: System.console => here System is namespace and console is class name
Assembly:
Assembly is a single deployable unit that contains all information about implementation of
classes, structure and interfaces. An assembly stores all information about itself and this information
called Meta data and includes the name and version number of assembly, security information and
information about dependencies, list of files that constitute assembly. All the application developed
using .NET framework made up of assembly. Namespaces are also stored in assemblies. Assemblies and
metadata provide the CLR with the information required for execution of an application. Assembly
provides this information to CLR while application is being executed. Assembly also plays an important
role in deployment and version control.
19
Explanation:
When you compile a program develop in a language that targets the CLR, instead of compiling
the source code into machine level code, the compiler translate it to Microsoft Intermediate Language
(MSIL) or Intermediate Language (IL). No matter which language has been used to develop the
application, it always gets translated into IL; this ensures language interoperability. Compiler also
produces Meta data about the program/ application during process of compilation. Meta data contains
description of program such as classes and interfaces, version of components stored in program. IL and
metadata linked in an assembly.
When you execute .exe/ .dll file, the IL and other information from base class library is sent to
class loader. Class loader loads code in memory.
Before code can be executed, .NET framework needs to convert the intermediate language into
native or CPU specific code. JIT compiler translates the code from IL to managed native code. During
20
Open Visual Studio 2010 and click on New Project; a dialog box will open, choose language VB and
from application choose Console Application.
Boolean
Byte
Char
DateTime
Decimal
Double
Int16
Int32
Int64
SByte
Single
TimeSpan
Write the following code in your Console Application code window
22
Key Points:
We can use System.Console.Write
System namespace is included in our programs, so it is optional to write System
Convert.int32 is used to convert string to integer type
Every read line is string by default, we have to convert it to specific type, we want to use.
23
Key Points:
24
Using if-else
Key Points:
Option Explicit ON => it will force you to declare each variable before it is being used
Option Explicit OFF
Option Strict ON => to stop automatic conversion like from int to long
Option Strict OFF
ByVal => to pass a parameter by value
ByRef => to pass a parameter by reference
We can comment a line by pressing in beginning of a line.
Boolean Operators:
o AND
o OR
o NOT
o XOR
o ANDALSO
o ORELSE
Looping
Assignment:
1. Print table of a number using for loop, do-while loop, do-until loop
2. Read a number from console and check whether it is prime or not
3. Ask two numbers from user and check which number is greater using conditional operator
26
27
Assignment
1. Addition of 2 matrix of order 2X2
2. Initially stores names of 5 students, then change array to hold 10 names and print 10 names
using for-each loop
3. Define a function factorial which returns factorial of a number
4. Make a subroutine which swaps two integers
5. Make a subroutine which swaps two integers without using third variable
6. Print following
1
12
123
1234
28
Using Select-Case
Function overloading
29
Assignment
1. Overload area() function to calculate area of circle and rectangle.
2. Overload sum() function to sum 2 integers, 2 doubles and 2 strings
3. Overload volume() function to calculate volume of cube, cylinder and cuboid
Defining Classes
Making a simple class
30
Creating constructor
31
Overloading constructor
32
Defining Properties
Key Points:
Properties can be readonly or writeonly also
Write readonly or writeonly keyword before property keyword while defining properties.
33
Operator Overloading
Assignment
1. Overload +,-,*,/ in complex class
a. You can use simple multiplication and division
2. Overload + and in matrix class of order 3 X 3
34
Inheritance
Code reusability
Time saving, cost saving
Types of inheritance
Single Level Inheritance
Multi level inheritance
Hierarchical Inheritance
Variable Scope
Private => accessible in member functions only
Protected => accessible in derived class also
Public => accessible outside the class also
How to inherit
35
36
Example
Main1
37
Main2
38
39
3. Create a base class called shape. Use this class to shore two double type values that could be
used to computer the area of figures. Derive two specific classes called triangle and rectangle
from the base shape. Add to the base class, a member function get_data() to initialize base class
data members and another member function display_area() to computer and display the area of
figures. Override display_area() in derive classes to suit their requireents.
Using these three classes, design a program that will accept dimensions of a triangle or a
rectangle interactively, and display the area.
Remember two values given as input will be treated as lengths of two sides in case of rectangles
and as base and height in case of triangles, and used as follows:
Area of rectangle = x * y
Area of triangle = *x*y
4. Extend the above program to display area of circles. This requires addition of a new derived class
circle that computes the area of a circle. Remember, for a circle we need only one value, its
radius, but the get_data() function in the base class requires two values to be passed. (Hint:
Make the second argument of get_data() function as a default/ optional one with zero value)
40
Abstract Classes
Explanation:
Abstract classes are used to create template for other classes.
We cant create object of abstract classes.
In VB.NET abstract classes are declared by the keyword mustinherit
As we cant create object of abstract class, so there is no use of defining any function, so we declare
functions/ subroutine with the keyword mustoverride
Example:
41
Interface
Explanation:
~ An alternative to abstract classes
~ less formality as compared to abstract classes
Example1
42
Example2
Implementing multiple interfaces
43
Example3
Inheriting interfaces
44
Example
Enumeration
Key points:
1. Default value is 0 for first name in enumeration
2. Rest all will get incremented value.
45
Example:
46
Understanding console
Creating Namespace
47
48
49
50
51
52
Understanding System.Environment
Getting User Name
Getting Current Directory
Getting System Directory
Getting Folder Path
Getting Operating System Version
Checking whether it is 64 bit OS or not
53
Understanding My.Computer
Getting GMT time
Checking various keys like caps lock, num lock, shift etc
Checking whether mouse is left handed or right handed
Getting computer name
Checking total physical memory
Checking total virtual memory
Checking available physical memory
Checking screen information, resolution etc
Getting OS platform
Getting culture
File System
54
Assignment
Try out various function of My.Computer.FileSystem at your own.
55
Using System.Collections
Stack
56
Queue
57
Assignment
There are lot many functions of strings. Try them at your own.
58
DateTime functions
Assignment:
1. Write a program to copy one file to another
2. Write a program which read from 2 files and write into third file
3. Write a program which read form one file and copy all even lines to second file and odd lines
to third file
4. Write a program which read input lines from users and save them in a file on desktop and
then read those lines from file and display it to user
Hint: use getfolderpath() to get path of desktop
5. Write a program for parsing using stack
6. Write a program which converts infix to postfix and evaluate the postfix expression
7. Write a program which converts infix to prefix and evaluate the prefix expression
59
Exception Handling
I am not covering theory part as every book has long stories on what are exceptions. Here we are
directly going to look at procedure to handle exceptions.
1.
2.
3.
4.
Try-Catch
60
61
Exception Class
-
62
63
Nested Try
In case inner try was not able to handle the exception, it will search catch in outer try.
64
65
Assignment
Try some examples on exceptions at your own
66
Windows Applications
I expect you are comfortable with Microsoft Visual Basic 6.0. Incase you dont have knowledge about
Visual Basic 6.0, I will suggest you to first go thru with that.
Here, we will be referring directly to the some common properties and some common events of
controls.
67
Remember:
In .NET, each control is having text property instead of text and caption property and the most
important line, everything is based on namespaces, classes and object is mother of all.
68
Remember:
Me refers to current form. In VB.NET, you cant use current form name in current form class, so
we will be use Me if we want to refer to current class.
6. To execute the application, press ctrl + F5 or simply press play button in toolbar
69
Change text properties from properties menu. I am here not changing name properties of controls; you
can change them as per your convenient.
And write button1_click event
70
Form
Button
CheckBox
CheckListBox
ColorDialog
Combo
ContextMenu
DataGrid (at a later stage)
DateTimePicker
DomainUpDown
ErrorProvider
FontDialog
GroupBox
HScrollBar
Label
LinkLabel
ListBox
ListView
MaskedTextBox
MenuStrip
MonthCalendar
NotifyIcon
NumericUpDown
OpenFileDialog
Pannel
PictureBox
ProgressBar
RadioButton
RichTextBox
SaveFileDialog
StatusStrip
TabControl
TextBox
Timer
ToolTip
ToolStrip
TrackBar
VScrollBar
71
MediaPlayer
WebBrowser
AdobePdf
TableLayout
FlowLayout
FolderBrowserDialog
PrintDialog
PrintForm
Animation Control
Drawing Graphics
MessageBox
InputBox
These controls are described in an order to make the reader comfortable and to make learning more
interesting.
72
Label
Properties window:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Events:
TextBox
Properties window:
Same as of label control, some new properties are shown here
1. Multiline = true ( you can write multiple lines in textbox; by default, textbox is single line)
2. Password char = * ( now the text appearing in textbox will be marked as * ; you can use any
character)
3. ReadOnly = True ( now user can read the text of textbox, he cant modify it)
4. ScrollBar = None / Horizontal / Vertical / Both
5. WordWrap = True
6. TabStop = True ( Using Tab key, you can focus on this control )
7. TabIndex, to set tab preference, when tab should appear on it.
I will recommend you to try all properties of properties window.
Events:
74
Form
Properties window:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
BackgroundImage
BackgroundImageLayout
ControlBox = False ( minimize, maximize and close button will not appear)
FormBorderStyle ( Try all these options and see effects)
MaximizeBox = False (Maximize button will get disable on form)
MinimizeBox
Opacity (to set transparency of Form, Try using with 80% and 50%, Default is 100%)
ShowInTaskbar = False (When you execute your form, your form will not appear in Taskbar)
Text = to change title bar text of form
TransparencyKey = white ( which color of form you want to be transparent, if I have selected
white, then the white color, wherever on form , will be transparent)
Events:
75
Button
Properties window:
Properties are similar to textbox and label, try them at your own.
Events:
76
2. Program it as
3. Now execute it
77
Again Confusion!!
1. Design same form again
2. Program it as
78
CheckBox
Properties window:
1. Checked: (Initially, when form is loaded, this checkbox will be checked or not)
2. ThreeState : True ( Then checkbox can have three states : Unchecked, Checked or intermediate )
Events:
Example:
Design your form as:
Program it as:
79
80
TrackBar
Properties Window:
1. Minimum and Maximum value
2. RightToLeft
3. Orientation : Horizontal or Vertical
Events:
Example:
81
VSrollBar
Example:
Assignment
Try HScrollBar at your own.
82
Timer
Simply drag the timer on your form. When you will drag, it will appear on the bottom bar IDE.
Property Window:
1. Enable: True ( to enable the timer, by default; its false)
2. Interval : duration after which timer will tick (1000 means 1 sec)
Example:
83
LinkLabel
It will appear as a link on form. You can do the normal working on its click event or you can browse
some website as it looks states.
Example:
84
ProgressBar
Example:
Simply drag a progressbar on your form. Change its minimum, maximum and style properties (if you
want)
Place a timer on your form. Change its interval to 1000 and enable to true
And program your timer as below and execute your program.
85
WebBrowser
Example:
Drag WebBrowser on your form. By Default it is docked in form. Click on Top Right Arrow appearing on
WebBrowser Control and choose undock
Initially, we are designing it with buttons, later you can create toolbar or menu bar and also you can use
images to change its Design.
86
Thats all we have to do and Thanks to Microsoft and our WebBrowser is ready!!!
MaskedTextBox
Use to specify a Mask/ Format.
Change its mask property and try it at your own. Its similar to TextBox except its mask property.
Try this at your own.
87
RadioButton
Example:
Design your form as:
88
A Big Confusion!!!
Design your form as:
And now execute your form and try to select one option from both groups!!!
89
Confusion Solved
Drag GroupBox from toolbox and design your form as:
90
ComboBox
Example:
Design your form as:
And execute it, choose one day from combo box and click submit.
91
Still, Confusion!!!
In above program, check carefully, user is able to change the text of ComboBox. User can edit the text of
combo box.
Confusion Solved:
Select the combo box and from properties menu, change its DropDownStyle to DropDownList.
92
ColorDialog
Example:
Simply drag color dialog on your form and program your form as:
And execute your form and click on form and change color
93
FontDialog
Example:
Drag font dialog on your form and design your form with a button and textbox and program it as:
94
FolderBrowserDialog
Example:
Drag FolderBrowserDialog and a button on form and program it as:
Using FolderBrowserDialog, you can ask user to select folder, where he wants to save files, and you can
get the path using FolderBrowserDialog.
Note: before showing this dialog, write
FolderBrowserDialog1.ShowNewFolderButton = False
95
OpenFileDialog
Example:
Drag OpenFileDialog and a button on form and program it as:
Now you know the file handling; so instead of displaying filename in msgbox, you can read its contents
and show in textbox or you can perform some operations. Basic idea is to show you how to use
OpenFileDialog.
Note: Try SaveFileDialog at your own.
96
AdobePdf
Example:
Drag AdobePdf, OpenFileDialog and a button on your form and program it as:
97
NumericUpDown
Example:
Drag NumericUpDown and a button on form. You can change minimum and maximum value of
NumericUpDown from properties menu. Program your button as:
98
MonthCalendar
Try this at your own. Try out all its properties. Its generally used to display calendar on form.
DateTimePicker
Using this control, you can get the value (Date) which user has selected.
Example:
Design your form as:
99
MessageBox
Till now, we are using Msgbox (), but this is a function of VB. Now we will be discussing MessageBox.
Variants of MessageBox:
InputBox
Its used to take a value from user. It will return a string; you have to convert it to specific type before
using.
Variants of InputBox:
100
ListBox
Example:
Simply drag a ListBox and a button on your form and program it as:
101
And now we have to retrieve all selected items, so we will program button_click as:
102
103
CheckListBox
Example:
Drag a CheckListBox and a button on form and program it as:
104
MenuStrip
Drag the MenuStrip on form. You can directly edit the menus you want to create.
Use if you want to create separator between menus. And you can assign ALT keys as shortcut by
writing & before that character.
105
To program it, simply double click that menu item, which you want to program.
106
ContextMenuStrip
Its is similar to MenuStrip except that it doesnt appear as normal menu bar, you have to assign
ContextMenu to some control, where user will right click to see the menu. Here, I am assigning
ContextMenu to TextBox as:
107
ErrorProvider:
Drag a textbox, a button and an error provider on form. Suppose we want to show an error message to
user, if textbox. Text is blank. We will write as:
108
RichTextBox
Have you noticed the difference between notepad and WordPad? In WordPad, you can paste pictures;
you can change background and foreground color of selected text, however in notepad, all this is not
possible. So, the alternate to TextBox is RichTextBox.
Drag it to your form. By default it is multiline. Lets look at some of its properties:
Assignment:
Make a Notepad Application using TextBox.
Enhance your notepad using RichTextBox.
109
FlowLayout
Used to draw controls. Like a Panel or GroupBox. Draw a FlowLayout on your form and place your
controls inside it. Controls will appear automatically in flowing locations. Try this at your own.
FlowLayout Example:
TableLayout
You will find using FlowLayout is quite difficult because we cant place controls at desired locations. One
alternative is TableLayout. You can place your controls in cells; you can insert some rows and columns
and can insert controls in cells. Try this control at your own.
TableLayout Example:
110
MediaPlayer
Drag MediaPlayer, 3 buttons and an OpenFileDialog on your form and design your form as:
111
Media Player has lots of properties. Try out all those properties.
112
ToolTip
Drag a ToolTip and a button on form. Suppose we want to show ToolTip on this button. Select button
and from its properties window, choose ToolTip on ToolTip1 and set it to any value.
And now select ToolTip control which you have dragged on form and from its properties menu, you can
set its icon, isBalloon and ToolTipTitle.
113
PictureBox
Drag a PictureBox on your form and click on arrow appearing on top right corner; change SizeMode
property to different options and check their effects. You can change image of PictureBox in two ways as
shown below. Use any one method at a time.
StatusStrip
Drag a StatusStrip on Form; it will appear at the bottom of Form. You can add label, ProgressBar and
Dropdown by clicking on the add new icon appearing on StatusStrip.
114
Example:
Here, on status label, I want to show the number of characters in RichTextBox.
And now execute your form, type something in RichTextBox and check status label.
115
ToolStrip
To create Toolbar. Drag ToolStrip on Form. By Default, it will appear on top corner. You can change its
back color, background image etc (Check its properties window). Here, I am setting back color to
transparent.
There is also an add new button appearing on ToolStrip, you can add new items by clicking on it.
Suppose we are adding a Button, by default it will appear as image, right click on image button and
change its display style like image and text. Now you can change its image by choosing set image option
from context menu and its text can be changed from properties menu. Here I have added two buttons:
You can program them by simply double clicking on them. In ToolStrip you can Buttons, Dropdown,
Label, Separators, Progress Bar, and TextBox.
116
117
TabControl
Drag a TabControl on your form. By default, only two tabs will be shown, you can add or remove tabs by
choosing TabPages from its properties menu. You can add your controls in it and program them. Now I
leave it to you, how creative you are!
Here are some properties which will help you:
Some Hints:
You can create MultiTab WebBrowser or you can create your notepad and tabbed menu to it.
Printing:
The simplest way, I found is- generate HTML report or open your document thru WebBrowser and user
will automatically do the page setup, print preview and print automaticallyWe dont have to do all that
stuff.
118
119
Animation:
We dont have animation control present in our toolbox; we have to add it explicitly. Right click the
toolbox and click choose items and from the dialog box, choose com components and from that choose
Microsoft Animation Control, and click ok.
It will add animation control to your Toolbox; now drag Animation Control to your form.
120
Animation Control can play .avi files, search for .avi files available on your PC. Generally, you have seen,
while copying files, animation plays on form. We will do something similar. Program your button as:
Note:
Bundle of images and animation comes with VisualStudio2010. You can found them in similar path of
the path shown below:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033\
Extract files and use them.
121
Graphics:
Here, we have created a line and a rectangle; there are many functions available for graphics, Again I
leave it on you, how creative you are!
NotifyIcon
It appears in System Tray.
Drag NotifyIcon control to your form, select it and change its properties (icon, text and title).
122
Note: Dont forget to set its icon property from property menu.
And now on button_click write
123
Assignment:
1. Design a Code Module for C++ or Java, like you have Visual Studio for .NET, Similar to this, Design
for C++ or Java, so that user dont have to write so much, Everything Drag and Drop and in
background, code will appear automatically and user can view, edit or save it.
124
Database Connectivity
ADO.NET
Here, I have tried to simplify the Database connectivity. The following figure explains how to connect
with database. We are showing here the connectivity with MS-Access, so that you can practice at home.
In the similar way, you can connect to SQL Server. MS-Access is not generally used because it can handle
only 35 clients at a time while SQL Server and Oracle can handle a large number of clients.
125
Displaying all records at a time using Data Adapter and Data Set
1.
2.
3.
4.
Open connection
Use Data Adapter to read from connection
Use Data Set to store data
And then display data from Data Set
Open windows application and drag DataGrid on it and program your form as:
126
127
Reading one value at a time using Data Adapter and Data Set
Design a form with just a Label on it and program it as:
128
129
130
131
Now, I leave up to you, how you will use these commands in your project.
Further, You can also add Exception handling in this.
132
The
MillenniumYear
Serial: 29062010172738
133