You are on page 1of 180

VB Dot Net

Before getting deeply into the subject we will first know how Businesses are related to Internet, what .NET means to them and what exactly .NET is built upon. s per the product documentation from a Business perspecti!e, there are three phases of the Internet. The "irst phase gets back to the early #$$%&s when Internet first came into general use and which brought a big re!olution for Businesses. In the "irst phase of the Internet Businesses designed and launched their 'ebsite&s and focused on the number of hits to know how many customers were !isiting their site and interested in their products, etc. The (econd phase is what we are in right now and in this phase Businesses are generating re!enue through )nline Transactions. 'e are now mo!ing into the Third phase of the Internet where profit is the main priority. The focus here is to Businesses effecti!ely communicate with their customers and partners who are geographically isolated, participate in *igital Economy and deli!er a wide range of ser!ices. +ow can that be possible, The answer, with .NET. What is .NET ? -any people reckon that it&s -icrosoft&s way of controlling the Internet, which is false. .NET is -icrosoft&s strategy of software that pro!ides ser!ices to people any time, any place, on any de!ice. n accurate definition of .NET is, it&s an .-/ 'eb (er!ices platform which allows us to build rich .NET applications, which allows users to interact with the Internet using wide range of smart de!ices 0tablet de!ices, pocket 12&s, web phones etc3, which allows to build and integrate 'eb (er!ices and which comes with many rich set of tools like 4isual (tudio to fully de!elop and build those applications. .NET vs Java -any of us wonder what .NET has to do with 5a!a. Is there any relation between them, re they similar, and so on. I e!en hear some people say .NET is -icrosoft&s answer to 5a!a. I think e!ery language has it&s own pros and cons. 5a!a is one of the greatest programming languages created by humans. 5a!a doesn&t ha!e a !isual interface and re6uires us to write heaps of code to de!elop applications. )n the other hand, with .NET, the "ramework supports around 7% different programming languages which are better and focus only on business logic lea!ing all other aspects to the "ramework. 4isual (tudio .NET comes with a rich !isual interface and supports drag and drop. -any applications were de!eloped, tested and maintained to compare the differences between .NET and 5a!a and the end result was a particular application de!eloped using .NET re6uires less lines of code, less time to de!elop and lower deployment costs along with other important issues. 1ersonally, I don&t mean to say that 5a!a is gone or .NET based applications are going to dominate the Internet but I think .NET definitely has an extra edge as it is packed with features that simplify application de!elopment. I hope the information abo!e puts some light on the technology aspects behind .NET and helps you in getting started.

.NET Framework
.NET is a 8(oftware 1latform8. It is a language9neutral en!ironment for de!eloping rich .NET experiences and building applications that can easily and securely operate within it. 'hen de!eloped applications are deployed, those applications will target .NET and will execute where!er .NET is implemented instead of targeting a particular +ardware:)( combination. The components that make up the .NET platform are collecti!ely called the .NET "ramework. The .NET "ramework is a managed, type9safe en!ironment for de!eloping and executing applications. The .NET "ramework manages all aspects of program execution, like, allocation of memory for the storage of data and instructions, granting and denying permissions to the application, managing execution of the application and reallocation of memory for resources that are not needed. The .NET "ramework is designed for cross9language compatibility. 2ross9 language compatibility means, an application written in 4isual Basic .NET may reference a *// file written in 2; 029(harp3. 4isual Basic .NET class might be deri!ed from a 2; class or !ice !ersa. The .NET "ramework consists of two main components< 2ommon /anguage =untime 02/=3 2lass /ibraries Common Language Runtime (CLR The 2/= is described as the 8execution engine8 of .NET. It&s this 2/= that manages the execution of programs. It pro!ides the en!ironment within which the programs run. The software !ersion of .NET is actually the 2/= !ersion. Working o! the CLR 'hen the .NET program is compiled, the output of the compiler is not an executable file but a file that contains a special type of code called the -icrosoft Intermediate /anguage 0-(I/3. This -(I/ defines a set of portable instructions that are independent of any specific 21>. It&s the job of the 2/= to translate this Intermediate code into a executable code when the program is executed making the program to run in any en!ironment for which the 2/= is implemented. nd that&s how the .NET "ramework achie!es 1ortability. This -(I/ is turned into executable code using a 5IT 05ust In Time3 complier. The process goes like this, when .NET programs are executed, the 2/= acti!ates the 5IT complier. The 5IT complier con!erts -(I/ into nati!e code on a demand basis as each part of the program is needed. Thus the program executes as a nati!e code e!en though it is compiled into -(I/ making the program to run as fast as it would if it is compiled to nati!e code but achie!es the portability benefits of -(I/.

C"ass Li#raries 2lass library is the second major entity of the .NET "ramework. This library gi!es the program access to runtime en!ironment. The class library consists of lots of prewritten code that all the applications created in 4B .NET and 4isual (tudio .NET will use. The code for all the elements like forms, controls and the rest in 4B .NET applications actually comes from the class library.

Common Language $%e&i!i&ation (CL$ If we want the code which we write in a language to be used by programs in other languages then it should adhere to the 2ommon /anguage (pecification 02/(3. The 2/( describes a set of features that different languages ha!e in common. The 2/( includes a subset of 2ommon Type (ystem 02T(3 which define the rules concerning data types and ensures that code is executed in a safe en!ironment. (ome reasons why de!elopers are building applications using the .NET "ramework< Impro!ed =eliability Increased 1erformance *e!eloper 1roducti!ity 1owerful (ecurity Integration with existing (ystems Ease of *eployment -obility (upport .-/ 'eb ser!ice (upport (upport for o!er 7% 1rogramming /anguages "lexible *ata ccess Brie!"' on some &hanges !rom VB (.) To Dot Net* The biggest change from 4B to 4B .NET is, 4B .NET is )bject9)riented now. 4B .NET now supports all the key ))1 features like Inheritance, 1olymorphism, bstraction and Encapsulation. 'e can now create classes and objects, deri!e classes from other classes and so on. The major ad!antage of ))1 is code reusability The 2ommand Button now is Button and the TextBox is TextBox instead of Text as in 4B? -any new controls ha!e been added to the toolbar to make application de!elopment more efficient 4B .NET now adds 2onsole pplications to it apart from 'indows and 'eb pplications. 2onsole applications are console oriented applications that run in the *)( !ersion ll the built9in 4B functionality now is encapsulated in a Namespace 0collection of different classes3 called (ystem New keywords are added and old one&s are either remo!ed or renamed

4B .NET is strongly typed which means that we need to declare all the !ariables by default before using them 4B .NET now supports structured exception handling using Try...2atch..."inally syntax The syntax for procedures is changed. @et and /et are replaced by @et and (et E!ent handling procedures are now passed only two parameters The way we handle data with databases is changed as well. 4B .NET now uses *) .NET, a new data handling model to communicate with databases on local machines or on a network and also it makes handling of data on the Internet easy. ll the data in *) .NET is represented in .-/ format and is exchanged in the same format. =epresenting data in .-/ format allows us for sending large amounts of data on the Internet and it also reduces network traffic when communicating with the database 4B .NET now supports -ultithreading. threaded application allows to do number of different things at once, running different execution threads allowing to use system resources 'eb *e!elopment is now an integral part of 4B .NET making 'eb "orms and 'eb (er!ices two major types of applications Visua" Basi& .NET 4isual Basic .NET pro!ides the easiest, most producti!e language and tool for rapidly building 'indows and 'eb applications. 4isual Basic .NET comes with enhanced !isual designers, increased application performance, and a powerful integrated de!elopment en!ironment 0I*E3. It also supports creation of applications for wireless, Internet9enabled hand9held de!ices. The following are the features of 4isual Basic .NET with .NET "ramework #.% and 4isual Basic .NET 7%%A with .NET "ramework #.#. This also answers why should I use 4isual Basic .NET, what can I do with it, +ower!u" Win,ows-#ase, .%%"i&ations 4isual Basic .NET comes with features such as a powerful new forms designer, an in9place menu editor, and automatic control anchoring and docking. 4isual Basic .NET deli!ers new producti!ity features for building more robust applications easily and 6uickly. 'ith an impro!ed integrated de!elopment en!ironment 0I*E3 and a significantly reduced startup time, 4isual Basic .NET offers fast, automatic formatting of code as you type, impro!ed Intelli(ense, an enhanced object browser and .-/ designer, and much more. Bui",ing We#-#ase, .%%"i&ations 'ith 4isual Basic .NET we can create 'eb applications using the shared 'eb "orms *esigner and the familiar 8drag and drop8 feature. Bou can double9click and write code to respond to e!ents. 4isual Basic .NET 7%%A comes with an enhanced +T-/ Editor for working with complex 'eb pages. 'e can also use Intelli(ense technology and tag completion, or choose the 'B(I'B@ editor for !isual authoring of interacti!e 'eb applications.

$im%"i!ie, De%"o'ment 'ith 4isual Basic .NET we can build applications more rapidly and deploy and maintain them with efficiency. 4isual Basic .NET 7%%A and .NET "ramework #.# makes 8*// +ell8 a thing of the past. (ide9by9side !ersioning enables multiple !ersions of the same component to li!e safely on the same machine so that applications can use a specific !ersion of a component. .2)1B9deployment and 'eb auto9download of 'indows9based applications combine the simplicity of 'eb page deployment and maintenance with the power of rich, responsi!e 'indows9based applications. +ower!u"/ F"e0i#"e/ $im%"i!ie, Data .&&ess Bou can tackle any data access scenario easily with *).NET and *) data access. The flexibility of *).NET enables data binding to any database, as well as classes, collections, and arrays, and pro!ides true .-/ representation of data. (eamless access to *) enables simple data access for connected data binding scenarios. >sing *).NET, 4isual Basic .NET can gain high9speed access to -( (C/ (er!er, )racle, *B7, -icrosoft ccess, and more. 1m%rove, Co,ing Bou can code faster and more effecti!ely. multitude of enhancements to the code editor, including enhanced Intelli(ense, smart listing of code for greater readability and a background compiler for real9time notification of syntax errors transforms into a rapid application de!elopment 0= *3 coding machine. Dire&t .&&ess to the +"at!orm 4isual Basic de!elopers can ha!e full access to the capabilities a!ailable in .NET "ramework #.#. *e!elopers can easily program system ser!ices including the e!ent log, performance counters and file system. The new 'indows (er!ice project template enables to build real -icrosoft 'indows NT (er!ices. 1rogramming against 'indows (er!ices and creating new 'indows (er!ices is not a!ailable in 4isual Basic .NET (tandard, it re6uires 4isual (tudio 7%%A 1rofessional, or higher. Fu"" 2#3e&t-2riente, Constru&ts Bou can create reusable, enterprise9class code using full object9oriented constructs. /anguage features include full implementation inheritance, encapsulation, and polymorphism. (tructured exception handling pro!ides a global error handler and eliminates spaghetti code. 45L We# $ervi&es .-/ 'eb ser!ices enable you to call components running on any platform using open Internet protocols. 'orking with .-/ 'eb ser!ices is easier where enhancements

simplify the disco!ery and consumption of .-/ 'eb ser!ices that are located within any firewall. .-/ 'eb ser!ices can be built as easily as you would build any class in 4isual Basic ?.%. The .-/ 'eb ser!ice project template builds all underlying 'eb ser!ice infrastructure.

5o#i"e .%%"i&ations 4isual Basic .NET 7%%A and the .NET "ramework #.# offer integrated support for de!eloping mobile 'eb applications for more than 7%% Internet9enabled mobile de!ices. These new features gi!e de!elopers a single, mobile 'eb interface and programming model to support a broad range of 'eb de!ices, including '-/ #.# for ' 1Denabled cellular phones, compact +T-/ 0c+T-/3 for i9-ode phones, and +T-/ for 1ocket 12, handheld de!ices, and pagers. 1lease note, 1ocket 12 programming is not a!ailable in 4isual Basic .NET (tandard, it re6uires 4isual (tudio 7%%A 1rofessional, or higher. C25 1ntero%era#i"it' Bou can maintain your existing code without the need to recode. 2)interoperability enables you to le!erage your existing code assets and offers seamless bi9 directional communication between 4isual Basic ?.% and 4isual Basic .NET applications. Reuse E0isting 1nvestments Bou can reuse all your existing cti!e. 2ontrols. 'indows "orms in 4isual Basic .NET 7%%A pro!ide a robust container for existing cti!e. controls. In addition, full support for existing *) code and data binding enable a smooth transition to 4isual Basic .NET 7%%A. 6%gra,e Wi7ar, Bou upgrade your code to recei!e all of the benefits of 4isual Basic .NET 7%%A. The 4isual Basic .NET >pgrade 'iEard, a!ailable in 4isual Basic .NET 7%%A (tandard Edition, and higher, upgrades up to $F percent of existing 4isual Basic code and forms to 4isual Basic .NET with new support for 'eb classes and >ser2ontrols. Names%a&es namespace is a collection of different classes. ll 4B applications are de!eloped using classes from the .NET (ystem namespace. The namespace with all the built9in 4B functionality is the (ystem namespace. ll other namespaces are based on this (ystem namespace. $ome Names%a&es an, their use*

(ystem< Includes essential classes and base classes for commonly used data types, e!ents, exceptions and so on (ystem.2ollections< Includes classes and interfaces that define !arious collection of objects such as list, 6ueues, hash tables, arrays, etc (ystem.*ata< Includes classes which lets us handle data from data sources (ystem.*ata.)le*b< Includes classes that support the )/E*B .NET pro!ider (ystem.*ata.(6l2lient< Includes classes that support the (C/ (er!er .NET pro!ider (ystem.*iagnostics< Includes classes that allow to debug our application and to step through our code (ystem.*rawing< 1ro!ides access to drawing methods (ystem.@lobaliEation< Includes classes that specify culture9related information (ystem.I)< Includes classes for data access with "iles (ystem.Net< 1ro!ides interface to protocols used on the internet (ystem.=eflection< Includes classes and interfaces that return information about types, methods and fields (ystem.(ecurity< Includes classes to support the structure of common language runtime security system (ystem.Threading< Includes classes and interfaces to support multithreaded applications (ystem.'eb< Includes classes and interfaces that support browser9ser!er communication (ystem.'eb.(er!ices< Includes classes that let us build and use 'eb (er!ices (ystem.'indows."orms< Includes classes for creating 'indows based forms (ystem..-/< Includes classes for .-/ support .ssem#"ies n assembly is the building block of a .NET application. It is a self describing collection of code, resources, and metadata 0data about data, example, name, siEe, !ersion of a file is metadata about that file3. n ssembly is a complied and !ersioned collection of code and metadata that forms an atomic functional unit. ssemblies take the form of a dynamic link library 0.dll3 file or executable program file 0.exe3 but they differ as they contain the information found in a type library and the information about e!erything else needed to use an application or component. ll .NET programs are constructed from these ssemblies. ssemblies are made of two parts< manifest, contains information about what is contained within the assembly and modules, internal files of I/ code which are ready to run. 'hen programming, we don&t directly deal with assemblies as the 2/= and the .NET framework takes care of that behind the scenes. The assembly file is !isible in the (olution Explorer window of the project. .n assem#"' in&"u,es< Information for each public class or type used in the assembly G information includes class or type names, the classes from which an indi!idual class is deri!ed, etc Information on all public methods in each class, like, the method name and return !alues 0if any3

Information on e!ery public parameter for each method like the parameter&s name and type Information on public enumerations including names and !alues Information on the assembly !ersion 0each assembly has a specific !ersion number3 Intermediate language code to execute list of types exposed by the assembly and list of other assemblies re6uired by the assembly Image of a ssembly file is displayed below.

Conso"e .%%"i&ations 2onsole pplications are command9line oriented applications that allow us to read characters from the console, write characters to the console and are executed in the *)( !ersion. 2onsole pplications are written in code and are supported by the (ystem.2onsole namespace. E0am%"e on a Conso"e .%%"i&ation 2reate a folder in 2< dri!e with any name 0say, examples3 and make sure the console applications which you open are sa!ed there. That&s for your con!enience. The default location where all the .NET applications are sa!ed is 2<H*ocuments and (ettingsH dministratorH-y *ocumentsH4isual (tudio 1rojects. The new project dialogue looks like the image below.

The following code is example of a console application<

-odule -odule# (ub -ain03 (ystem.2onsole.'rite08'elcome to 2onsole pplications83 End (ub End -odule Bou run the code by selecting *ebug9I(tart from the main menu or by pressing "F on the keyboard. The result 8'elcome to 2onsole pplications8 displayed on a *)( window. lternati!ely, you can run the program using the 4B compiler 0!bc3. To do that, go to the 4isual (tudio. NET command prompt selecting from (tart9I1rograms9I4isual (tudio.NET9I4isual (tudio.NET Tools9I4isual (tudio.NET 2ommand 1rompt and type< c<HexamplesI!bc example#.!b. :: is to compile the program

Then c<HexamplesIexample# :: to run the program The result, 8'elcome to 2onsole pplications8 is displayed on a *)( window as shown in the image below.

Breaking the 2ode to understand it Note the first line, we&re creating a 4isual Basic -odule and -odules are designed to hold code. ll the code which we write should be within the -odule. Next line starts with (ub -ain03, the entry point of the program. The third line indicates that we are using the 'rite method of the (ystem.2onsole class to write to the console. Commenting the Co,e 2omments in 4B.NET begin with a single 6uote 0&3 character and the statements following that are ignored by the compiler. 2omments are generally used to specify what is going on in the program and also gi!es an idea about the flow of the program. The general form looks like this< *im I as Integer &declaring an integer 2ode Data T'%es/ .&&ess $%e&i!iers Data T'%es in VB .NET The *ata types a!ailable in 4B .NET, their siEe, type, description are summariEed in the table below.

Data Type

Size in Bytes

Description

Type

Byte

8-bit unsigned integer

System.Byte

Char

16-bit Unicode characters

System.Char

nteger

"2-bit signed integer

System. nt"2

Doub#e

6!-bit $#oating point %ariab#e

System.Doub#e

&ong

6!-bit signed integer

System. nt6!

Short

16-bit signed integer

System. nt16

Sing#e

"2-bit $#oating point %ariab#e

System.Sing#e

String

'aries

(on-(umeric Type

System.String

Date

System.Date

Boo#ean

(on-(umeric Type

System.Boo#ean

)b*ect

(on-(umeric Type

System.)b*ect

Decima#

16

128-bit $#oating point %ariab#e

System.Decima#

.&&ess $%e&i!iers ccess specifiers let&s us specify how a !ariable, method or a class can be used. The following are the most commonly used one&s< 1ublic< @i!es !ariable public access which means that there is no restriction on their accessibility 1ri!ate< @i!es !ariable pri!ate access which means that they are accessible only within their declaration content 1rotected< 1rotected access gi!es a !ariable accessibility within their own class or a class deri!ed from that class "riend< @i!es !ariable friend access which means that they are accessible within the program that contains their declaration 1rotected "riend< @i!es a !ariable both protected and friend access

(tatic< -akes a !ariable static which means that the !ariable will hold the !alue e!en the procedure in which they are declared ends (hared< *eclares a !ariable that can be shared across many instances and which is not associated with a specific instance of a class or structure =ead)nly< -akes a !ariable only to be read and cannot be written Varia#"es 4ariables are used to store data. !ariable has a name to which we refer and the data type, the type of data the !ariable holds. 4B .NET now needs !ariables to be declared before using them. 4ariables are declared with the *im keyword. *im stands for *imension. Example Imports (ystem.2onsole -odule -odule# (ub -ain03 *im a,b,c as Integer &declaring three !ariables of type integer aJ#% bJ7% cJaKb 'rite08(um of a and b is8 L c3 End (ub End -odule

$tatements an, $&o%e $tatements statement is a complete instruction. It can contain keywords, operators, !ariables, literals, expressions and constants. Each statement in 4isual Basic should be either a declaration statement or a executable statement. declaration statement is a statement that can create a !ariable, constant, data type. They are the one&s we generally use to declare our !ariables. )n the other hand, executable statements are the statements that perform an action. They execute a series of statements. They can execute a function, method, loop, etc.

2%tion $tatement The )ption statement is used to set a number of options for the code to pre!ent syntax and logical errors. This statement is normally the first line of the code. The )ption !alues in 4isual Basic are as follows. )ption 2ompare< Bou can set it&s !alue to Text or Binary. This specifies if the strings are compared using binary or text comparison operators. )ption Explicit< *efault is )n. Bou can set it to )ff as well. This re6uires to declare all the !ariables before they are used. )ption (trict< *efault is )ff. Bou can set it to )n as well. >sed normally when working with con!ersions in code. If you want to assign a !alue of one type to another then you should set it to )n and use the con!ersion functions else 4isual Basic will consider that as an error. E0am%"e o! 2%tion $tatement The following code demonstrates where to place the )ption statement. )ption (trict )ff Imports (ystem -odule -odule # (ub -ain 03 2onsole.'rite/ine 0M>sing )ptionN3 End (ub End -odule The following code throws an error because )ption (trict is )n and the code attempts to con!ert a !alue of type double to integer. )ption (trict )n Imports (ystem.2onsole -odule -odule7 (ub -ain03 *im i s Integer *im d s *ouble J 7%.#7 iJd 'rite/ine0i3 End (ub End -odule

'e always should program with )ption (trict )n. *oing so allows us to catch many errors at compile time that would otherwise be difficult to track at run time. 1m%orts $tatement The Imports statement is used to import namespaces. >sing this statement pre!ents you to list the entire namespace when you refer to them. E0am%"e o! 1m%orts $tatement The following code imports the namespace (ystem.2onsole and uses the methods of that namespace pre!enting us to refer to it e!ery time we need a method of this namespace. Imports (ystem.2onsole -odule -odule# (ub -ain03 'rite08Imports (tatement83 'rite/ine08>sing Import83 End (ub End -odule The abo!e two methods without an imports statement would look like this< (ystem.2onsole.'rite08Imports (tatement83 and (ystem.2onsole.'rite/ine08>sing Import83 With $tatement 'ith statemnt is used to execute statements using a particular object. The syntax looks like this< 'ith object OstatementsP End 'ith $am%"e Co,e The following code sets text and width for a button using the 'ith (tatement. 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles -yBase./oad

'ith Button# .Text J 8'ith (tatement8 .'idth J #F% End 'ith End (ub Bo0ing Boxing is implicit con!ersion of !alue types to reference types. =ecall that all classes and types are deri!ed from the )bject class. Because they are deri!ed from )bject class they can be implicitly con!erted to that type. The following sample shows that< *im x as IntegerJ7% &declaring an integer x *im o as )bject &declaring an object oJx con!erting integer to object >nboxing is the con!ersion of a boxed !alue back to a !alue type. $&o%e The scope of an element in code is all the code that can refer to it without 6ualifying it&s name. (tated other way, an element&s scope is it&s accessibility in code. (cope is normally used when writing large programs as large programs di!ide code into different classes, modules, etc. lso, scope pre!ents the chance of code referring to the wrong item. The different kinds of scope a!ailable in 4B .NET are as follows< Block (cope< The element declared is a!ailable only within the code block in which it is declared. 1rocedure (cope< The element declared is a!ailable only within the procedure in which it is declared. -odule (cope< The element is a!ailable to all code within the module and class in which it is declared. Namespace (cope< The element declared is a!ailable to all code in the namespace. 5etho,s -ethod is a procedure built into the class. They are a series of statements that are executed when called. -ethods allow us to handle code in a simple and organiEed fashion. There are two types of methods in 4B .NET< those that return a !alue 0"unctions3 and those that do not return a !alue 0(ub 1rocedures3. Both of them are discussed below.

$u# +ro&e,ures (ub procedures are methods which do not return a !alue. Each time when the (ub procedure is called the statements within it are executed until the matching End (ub is encountered. (ub -ain03, the starting point of the program itself is a sub procedure. 'hen the application starts execution, control is transferred to -ain (ub procedure automatically which is called by default. Example of a (ub 1rocedure -odule -odule# (ub -ain03 &sub procedure -ain03 is called by default *isplay03 &sub procedure display03 which we are creating End (ub (ub *isplay03 (ystem.2onsole.'rite/ine08>sing (ub 1rocedures83 &executing sub procedure *isplay03 End (ub End -odule )utput 6sing $u# +ro&e,ures

Fun&tions "unction is a method which returns a !alue. "unctions are used to e!aluate data, make calculations or to transform data. *eclaring a "unction is similar to declaring a (ub procedure. "unctions are declared with the "unction keyword. The following code is an example on "unctions< Imports (ystem.2onsole -odule -odule#

(ub -ain03 'rite08(um is8 L 8 8 L dd033 &calling the function End (ub 1ublic "unction dd03 s Integer &declaring a function add *im i, j s Integer &declaring two integers and assigning !alues to them i J #% j J 7% =eturn 0i K j3 &performing the sum of two integers and returning it&s !alue End "unction End -odule )utput $um is 8)

Ca""ing 5etho,s method is not executed until it is called. method is called by referencing it&s name along with any re6uired parameters. "or example, the abo!e code called the dd method in (ub main like this<'rite08(um is8 L 8 8 L dd033. 5etho, Varia#"es 4ariables declared within methods are called method !ariables. They ha!e method scope which means that once the method is executed they are destroyed and their memory is reclaimed. "or example, from the abo!e code 0"unctions3 the dd method declared two integer !ariables i, j. Those two !ariables are accessible only within the method and not from outside the method. +arameters parameter is an argument that is passed to the method by the method that calls it. 1arameters are enclosed in parentheses after the method name in the method

declaration. Bou must specify types for these parameters. The general form of a method with parameters looks like this< 1ublic "unction dd0By4al x# as Integer, By4al y# as Integer3 999999999999 Implementation 999999999999 End "unction 1!....E"se statement If conditional expression is one of the most useful control structures which allows us to execute a expression if a condition is true and execute a different expression if it is "alse. The syntax looks like this< If condition Then OstatementsP Else If condition Then OstatementsP 99999 Else OstatementsP End If 6n,erstan,ing the $'nta0 If the condition is true, the statements following the Then keyword will be executed, else, the statements following the ElseIf will be checked and if true, will be executed, else, the statements in the else part will be executed. Example Imports (ystem.2onsole -odule -odule# (ub -ain03 *im i s Integer 'rite/ine08Enter an integer, # or 7 or A83 i J 4al0=ead/ine033 &=ead/ine03 method is used to read from console If i J # Then 'rite/ine08)ne83 ElseIf i J 7 Then

'rite/ine08Two83 ElseIf i J A Then 'rite/ine08Three83 Else 'rite/ine08Number not #,7,A83 End If End (ub End -odule )utput Enter an integer/ 9 or : or 8 : Two

$e"e&t....Case $tatement The (elect 2ase statement executes one of se!eral groups of statements depending on the !alue of an expression. If your code has the capability to handle different !alues of a particular !ariable then you can use a (elect 2ase statement. Bou use (elect 2ase to test an expression, determine which of the gi!en cases it matches and execute the code in that matched case. The syntax of the (elect 2ase statement looks like this< (elect 2ase testexpression O2ase expressionlist9n Ostatements9nPP . . . O2ase Else elsestatementsP End (elect Example Imports (ystem.2onsole -odule -odule# (ub -ain03

*im keyIn s Integer 'rite/ine08Enter a number between # and R83 keyIn J 4al0=ead/ine033 (elect 2ase keyIn 2ase # 'rite/ine08Bou entered #83 2ase 7 'rite/ine08Bou entered 783 2ase A 'rite/ine08Bou entered A83 2ase R 'rite/ine08Bou entered R83 End (elect End (ub End -odule )utput Enter a num#er #etween 9 an, ; : <ou entere, : -----------------------------For Loo% The "or loop is the most popular loop. "or loops enable us to execute a series of expressions multiple numbers of times. The "or loop in 4B .NET needs a loop index which counts the number of loop iterations as the loop executes. The syntax for the "or loop looks like this< "or indexJstart to endO(tep stepP OstatementsP OExit "orP OstatementsP NextOindexP The index !ariable is set to start automatically when the loop starts. Each time in the loop, index is incremented by step and when index e6uals end, the loop ends.

Example on "or loop -odule -odule# (ub -ain03 *im d s Integer "or d J % To 7 (ystem.2onsole.'rite/ine08In the "or /oop83 Next d End (ub End -odule )utput 1n the For Loo% 1n the For Loo% 1n the For Loo% ---------------------------Whi"e "oo% 'hile loop keeps executing until the condition against which it tests remain true. The syntax of while loop looks like this< 'hile condition OstatementsP End 'hile Example on 'hile loop -odule -odule# (ub -ain03 *im d, e s Integer dJ% eJ? 'hile e I R e 9J # d KJ # End 'hile

(ystem.2onsole.'rite/ine08The /oop ran 8 L e L 8times83 End (ub End -odule )utput The Loo% ran ;times -----------------------------Do Loo% The *o loop can be used to execute a fixed block of statements indefinite number of times. The *o loop keeps executing it&s statements while or until the condition is true. Two keywords, while and until can be used with the do loop. The *o loop also supports an Exit *o statement which makes the loop to exit at any moment. The syntax of *o loop looks like this< *oOSwhile T >ntilU conditionP OstatementsP OExit *oP OstatementsP /oop Example on *o loop -odule -odule# (ub -ain03 *im str s (tring *o >ntil str J 82ool8 (ystem.2onsole.'rite/ine08'hat to do,83 str J (ystem.2onsole.=ead/ine03 /oop End (ub End -odule )utput What to ,o? What to ,o?

What to ,o? What to ,o? Coo" -----------------------------Data T'%e Conversion/ Fi"e E0tensions Converting #etween Data t'%es In 4isual Basic, data can be con!erted in two ways< implicitly, which means the con!ersion is performed automatically, and explicitly, which means you must perform the con!ersion. 1m%"i&t Conversions /et&s understand implicit con!ersions in code. The example below declares two !ariable, one of type double and the other integer. The double data type is assigned a !alue and is con!erted to integer type. 'hen you run the code the result displayed is an integer !alue, in this case the !alue displayed is #A7 instead of #A7.A#77A. Imports (ystem.2onsole -odule -odule# (ub -ain03 *im dJ#A7.A#77A as *ouble *im i as Integer iJd 'rite/ine08Integer !alue is8 L i3 End (ub End -odule E0%"i&it Conversions 'hen types cannot be implicitly con!erted you should con!ert them explicitly. This con!ersion is also called as cast. Explicit con!ersions are accomplished using 2Type function. CT'%e !un&tion !or &onversion If we are not sure of the name of a particular con!ersion function then we can use the 2Type function. The abo!e example with a 2Type function looks like this<

Imports (ystem.2onsole -odule -odule# (ub -ain03 *im d s *ouble d J #A7.A#77A *im i s Integer i J 2Type0d, i3 &two arguments, type we are con!erting from, to type desired 'rite/ine08Integer !alue is8 L i3 End (ub End -odule Below is the list of con!ersion functions which we can use in 4B .NET. 2Bool 9 use this function to con!ert to Bool data type 2Byte 9 use this function to con!ert to Byte data type 22har 9 use this function to con!ert to 2har data type 2*ate 9 use this function to con!ert to *ate type 2*bl 9 use this function to con!ert to *ouble data type 2*ec 9 use this function to con!ert to *ecimal data type 2Int 9 use this function to con!ert to Integer data type 2/ng 9 use this function to con!ert to /ong data type 2)bj 9 use this function to con!ert to )bject type 2(hort 9 use this function to con!ert to (hort data type 2(ng 9 use this function to con!ert to (ingle data type 2(tring 9 use this function to con!ert to (tring data type Fi"e E0tensions in VB .NET The files and their extensions which are created as part of the 'indows pplication 1roject and their meaning are summariEed below< .!bproj9I 4isual Basic project "orm#.!b9I form&s code ssemblyInfo.4B9IInformation about an assembly, includes !ersion information .!bproj.user9I(tores project user options .sln9I(olution file which stores solution&s configuration .suo9I (tores (olution user options "orm#.resx.NET9I.-/ based resource template bin directory9I*irectory for binary executables obj directory9I*irectory for debugging binaries Language Termino"og'

Briefly on some terminology when working with the language< -odule< >sed to hold code 4ariable< named memory location of a specific data type used to hold some !alue 1rocedure< callable series of statements which may or may not return a !alue (ub91rocedure< procedure with no return !alue "unction< procedure with return !alue -ethods< procedure built into the class 2onstructor< (pecial method used to initialiEe and customiEe the object. It has the same name as the class 2lass< n ))1 class which contains data and code )bject< n instance of a class rrays< 1rogramming constructs that lets us access data by numeric index 2%erators 4isual Basic comes with many built9in operators that allow us to manipulate data. n operator performs a function on one or more operands. "or example, we add two !ariables with the 8K8 addition operator and store the result in a third !ariable with the 8J8 assignment operator like this< int x K int y J int E. The two !ariables 0x ,y3 are called operands. There are different types of operators in 4isual Basic and they are described below in the order of their precedence. .rithmeti& 2%erators rithmetic operators are used to perform arithmetic operations that in!ol!e calculation of numeric !alues. The table below summariEes them<

)perator

Use

,-ponentiation

(egation .used to re%erse the sign o$ the gi%en %a#ue/ e-p -int'a#ue0

2u#tip#ication

Di%ision

nteger Di%ision

2od

2odu#us 5rithmetic

5ddition

Subtraction

Con&atenation 2%erators 2oncatenation operators join multiple strings into a single string. There are two concatenation operators, K and L as summariEed below<

)perator

Use

String Concatenation

String Concatenation

Com%arison 2%erators comparison operator compares operands and returns a logical !alue based on whether the comparison is true or not. The table below summariEes them<

)perator 8 :; : ; ;8 :8

Use ,9ua#ity ne9ua#ity &ess than <reater than <reater than or e9ua# to &ess than or e9ua# to

Logi&a" = Bitwise 2%erators The logical operators compare Boolean expressions and return a Boolean result. In short, logical operators are expressions which return a true or false result o!er a conditional expression. The table below summariEes them<

)perator

Use

(ot

(egation

5nd

Con*unction

5nd5#so

Con*unction

)r

Dis*unction

)r,#se

Dis*unction

=or

Dis*unction

Co,e $am%"es .rithmeti& 2%erators Imports (ystem.2onsole -odule -odule# (ub -ain03 *im x, y, E s Integer x J A% y J 7% EJxKy 'rite/ine08 ddition8 L 8 J 8 L E3 EJx9y 'rite/ine08(ubtraction8 L 8 J 8 L E3 EJxVy 'rite/ine08-ultiplication8 L 8 J 8 L E3 EJx:y 'rite/ine08*i!ision8 L 8 J 8 L E3 =ead03 End (ub End -odule )utput .,,ition > ?) $u#tra&tion > 9) 5u"ti%"i&ation > ())

Division > : -----------------------------Con&atenation 2%erators Imports (ystem.2onsole -odule -odule# (ub -ain03 *im str#, str7, strA, strR s (tring str# J 82oncatenation8 str7 J 8)perators8 strA J str# K str7 'rite/ine0strA3 strR J str# L str7 'rite/ine0strR3 =ead03 End (ub End -odule )utput Co&atenation2%erators Co&atenation2%erators -----------------------------Com%arison 2%erators Imports (ystem.2onsole -odule -odule# (ub -ain03 *im x, y s Integer 'rite/ine08enter !alues for x and y 83 x J 4al0=ead/ine033 y J 4al0=ead/ine033 If x J y Then 'rite/ine08x is e6ual to y83 ElseIf x W y Then

'rite/ine08x is less than y83 ElseIf x I y Then 'rite/ine08x is greater than y83 End If =ead03 End (ub End -odule )utput Enter va"ues !or 0 an, ' 9? :) 0 is "ess than '

Logi&a" = Bitwise 2%erators Imports (ystem.2onsole -odule -odule# (ub -ain03 *im x s Boolean x J Not RF I 7? 'rite/ine08x not is false83 & x e6uals false x J Not 7? I XY & x e6uals True 'rite/ine08x not is true83 =ead03 End (ub End -odule )utput 4 not is !a"se

4 not is true -----------------------------Enumeration/ E0&e%tion @an,"ing Enumeration Enumeration is a related set of constants. They are used when working with many constants of the same type. It&s declared with the Enum keyword. Example Imports (ystem.2onsole -odule -odule# Enum (easons (ummer J # 'inter J 7 (pring J A utumn J R End Enum (ub -ain03 'rite08(ummer is the8 L (easons.(ummer L 8season83 End (ub End -odule )utput of abo!e code is below. To use a constant from the enumeration it should be referred like this, (easons.'inter and so on. $ummer is the 9 season ----------------------------Constants 'hen we ha!e certain !alues that we fre6uently use while programming, we should use 2onstants. !alue declared as constant is of fixed !alue that cannot be changed once set. 2onstants should be declared as 1ublic if we want it to be accessed by all parts of the application. In 4isual Basic .NET we use the 2onst keyword to declare a constant. The following line of code declares a constant< 1ublic 2onst 1i as *oubleJA.#R#F$7?F E0&e%tion @an,"ing

Exceptions are runtime errors that occur when a program is running and causes the program to abort without execution. (uch kind of situations can be handled using Exception +andling. By placing specific lines of code in the application we can handle most of the errors that we may encounter and we can enable the application to continue running. 4B .NET supports two ways to handle exceptions, >nstructured exception +andling using the on error goto statement and (tructured exception handling using Try....2atch....."inally /et&s look at the new kind of exception handling introduced in 4B .NET which is the (tructured Exception +andling. 4B .NET uses Try....2atch...."inally block type exception handling. The syntax looks like this< -odule -odule# (ub -ain03 Try 9 9 2atch e as Exception 9 9 "inally End Try End (ub End -odule Example Imports (ystem.2onsole -odule -odule# (ub -ain03 *im a J %, b J #, c s Integer Try cJb:a &the abo!e line throws an exception 'rite/ine082 is 8 L c3 2atch e s Exception 'rite/ine0e3 &catching the exception End Try End (ub End -odule

The output of the abo!e code displays a message stating the exception. The reason for the exception is because any number di!ided by Eero is infinity. 'hen working with (tructured exception handling you can ha!e multiple 2atch blocks to handle different types of exceptions differently. The code in the "inally block is optional. If there is a "inally block in the code then that code is executed last. )utput The +ro%er Error 5essage Wi"" #e Dis%"a'e, -----------------------------.rra's rrays are programming constructs that store data and allow us to access them by numeric index or subscript. rrays helps us create shorter and simpler code in many situations. rrays in 4isual Basic .NET inherit from the rray class in the (ystem namespace. ll arrays in 4B as Eero based, meaning, the index of the first element is Eero and they are numbered se6uentially. Bou must specify the number of array elements by indicating the upper bound of the array. The upper bound is the numder that specifies the index of the last element of the array. rrays are declared using *im, =e*im, (tatic, 1ri!ate, 1ublic and 1rotected keywords. n array can ha!e one dimension 0liinear arrays3 or more than one 0multidimensional arrays3. The dimensionality of an array refers to the number of subscripts used to identify an indi!idual element. In 4isual Basic we can specify up to A7 dimensions. rrays do not ha!e fixed siEe in 4isual Basic. The following code demonstrates arrays. Imports (ystem.2onsole -odule -odule# (ub -ain03 *im sport0F3 s (tring &declaring an array sport0%3 J 8(occer8 sport0#3 J 82ricket8 sport073 J 8=ugby8 sport0A3 J 8 ussie =ules8 sport0R3 J 8BasketBall8 sport0F3 J 8+ockey8 &storing !alues in the array 'rite/ine08Name of the (port in the third location8 L 8 8 L sport0733 &displaying !alue from array End (ub End -odule

6n,erstan,ing the Co,e The abo!e code declared a sport array of type string like this< *im sport0F3 as (tring. This sport array has ? elements starting from sport0%3 to sport0F3. The first element of an array is always referred by Eero index. The )utput below displays output from abo!e code. Name o! the $%ort in thir, "o&ation Rug#' -----------------------------Bou can also declare an array without specifying the number of elements on one line, you must pro!ide !alues for each element when initialiEing the array. The following lines demonstrate that< *im Test03 as Integer &declaring a Test array TestJNew Test03S#,A,F,Y,$,U Reinitia"i7ing .rra's 'e can change the siEe of an array after creating them. The =e*im statement assigns a completely new array object to the specified array !ariable. Bou use =e*im statement to change the number of elements in an array. The following lines of code demonstrate that. This code reinitialiEes the Test array declared abo!e. *im Test0#%3 as Integer =e*im Test07F3 as Integer &=einitialiEing the array 'hen using the =edim statement all the data contained in the array is lost. If you want to preser!e existing data when reinitialiEing an array then you should use the 1reser!e keyword which looks like this< *im Test03 as IntegerJS#,A,FU &declares an array an initialiEes it with three members =e*im 1reser!e Test07F3 &resiEes the array and retains the the data in elements % to 7 5u"ti,imensiona" .rra's

ll arrays which were mentioned abo!e are one dimensional or linear arrays. There are two kinds of multidimensional arrays supported by the .NET framework< =ectangular arrays and 5agged arrays. Re&tangu"ar arra's =ectangular arrays are arrays in which each member of each dimension is extended in each other dimension by the same length. 'e declare a rectangular array by specifying additional dimensions at declaration. The following lines of code demonstrate the declaration of a multidimensional array. *im rect rray0R, 73 s Integer &declares an array of F by A members which is a #F member array *im rect rray0,3 s Integer J SS#, 7, AU, S#7, #A, #RU, S##, #%, $UU &setting initial !alues Jagge, .rra's nother type of multidimensional array, 5agged rray, is an array of arrays in which the length of each array can differ. Example where this array can be used is to create a table in which the number of columns differ in each row. (ay, if row# has A columns, row7 has A columns then rowA can ha!e R columns, rowR can ha!e F columns and so on. The following code demonstrates jagged arrays. *im colors07303 as (tring &declaring an array of A arrays colors0%3JNew (tring03S8=ed8,8blue8,8@reen8U initialiEing the first array to A members and setting !alues colors0#3JNew (tring03S8Bellow8,81urple8,8@reen8,84iolet8U initialiEing the second array to R members and setting !alues colors073JNew (tring03S8=ed8,8Black8,8'hite8,8@rey8,8 6ua8U initialiEing the third array to F members and setting !alues $trings/ 5ath Fun&tions $trings (trings in 4isual Basic are supported by the .NET (tring class. The (tring data type can represent a series of characters and can contain approximately up to 7 billion >nicode characters. There are many built9in functions in the (tring class. (ome .NET "ramework functions are also built into the (tring class. The following code puts some (tring functions to work.

Imports (ystem.2onsole -odule -odule# (ub -ain03 *im string# s (tring J 8(trings in 4isual Basic8 *im string7 s (tring *im stringA s (tring *im stringR s (tring *im stringF s (tring *im string? s (tring string7 J >2ase0string#3 &con!erts string to uppercase stringA J /2ase0string#3 &con!erts string to lowercase stringR J string#.(ubstring0##, ?3 &returns a substring stringF J string#.2lone &clones a string string? J string#.@et+ash2ode &gets the hashcode 'rite/ine0string73 'rite/ine0stringA3 'rite/ine0stringR3 'rite/ine0stringF3 'rite/ine0string?3 =ead03 End (ub End -odule )utput $TR1NA$ 1N V1$6.L B.$1C strings in visua" #asi& Visua" $trings in Visua" Basi& -99?;?)B:C) -----------------------------5ath Fun&tions

4isual Basic pro!ides support for handling -athematical calculations. -ath functions are stored in (ystem.-ath namespace. 'e need to import this namespace when we work with -ath functions. The functions built into -ath class helps us calculate the Trigonometry !alues, (6uare roots, logarithm !alues, etc. The following code puts some -ath functions to work. Imports (ystem.2onsole Imports (ystem.-ath -odule -odule# (ub -ain03 'rite/ine08(ine $% is8 L 8 8 L (in0$%33 &display (ine$% !alue 'rite/ine08(6uare root of X# is 8 L 8 8 L (6rt0X#33 &displays s6uare root of X# 'rite/ine08/og !alue of #7 is8 L 8 8 L /og0#733 &displays the logarithm !alue of #7 =ead03 End (ub End -odule )utput $ine B) iss ).DB8BB(((8())??D $Euare root o! D9 is B Log va"ue o! 9: is :.;D;B)((;BCDD

Visua" $tu,io .NET 1DE 4isual (tudio .NET I*E 0Integrated *e!elopment En!ironment3 is the *e!elopment En!ironment for all .NET based applications which comes with rich features. 4B .NET I*E pro!ides many options and is packed with many features that simplify application de!elopment by handling the complexities. 4isual (tudio .NET I*E is an enhancement to all pre!ious I*EZs by -icrosoft. 1m%ortant Features 2ne 1DE !or a"" .NET +ro3e&ts

4isual (tudio .NET I*E pro!ides a single en!ironment for de!eloping all types of .NET applications. pplicationZs range from single windows applications to complex n9 tier applications and rich web applications. 2%tion to &hoose !rom 5u"ti%"e +rogramming Languages Bou can choose the programming language of your choice to de!elop applications based on your expertise in that language. Bou can also incorporate multiple programming languages in one .NET solution and edit that with the I*E. 1DE is Customi7a#"e Bou can customiEe the I*E based on your preferences. The -y 1rofile settings allow you to do this. 'ith these settings you can set the I*E screen the way you want, the way the keyboard beha!es and you can also filter the help files based on the language of your choice. Bui"t-in Browser The I*E comes with a built9in browser that helps you browse the Internet without launching another application. Bou can look for additional resources, online help files, source codes and much more with this built9in browser feature. 'hen we open 4B .NET from (tart9I1rograms9I-icrosoft 4isual (tudio .NET9 I-icrosoft 4isual (tudio .NET the window that is displayed first is the (tart 1age which is shown below. The start 1age allows us to select from the most recent projects 0last four 1rojects3 with which we worked or it can be customiEed based on your preferences.

The Integrated *e!elopment En!ironment 0I*E3 shown in the image below is what we actually work with. This I*E is shared by all programming languages in 4isual (tudio. Bou can !iew the toolbars towards the left side of the image along with the (olution Explorer window towards the right.

New +ro3e&t Dia"ogue Bo0 The New 1roject dialogue box like the one in the image below is used to create a new project specifying it&s type allowing us to name the project and also specify it&s location on the disk where it is sa!ed. The default location on the hard disk where all the projects are sa!ed is

2<H*ocumentsand(ettingsH dministratorH-y*ocumentsH4isual(tudio1rojects.

"ollowing are different templates under 1roject Types and their use. Win,ows .%%"i&ation< This template allows to create standard windows based applications. C"ass Li#rar'< 2lass libraries are those that pro!ide functionality similar to cti!e . and *// by creating classes that access other applications. Win,ows Contro" Li#rar'< This allows to create our own windows controls. lso called as >ser 2ontrols, where you group some controls, add it to the toolbox and make it a!ailable to other projects. .$+ .NET We# .%%"i&ation < This allows to create web9based applications using II(. 'e can create web pages, rich web applications and web ser!ices. .$+ .NET We# $ervi&e< llows to create .-/ 'eb (er!ices. We# Contro" Li#rar'< llows to create >ser9defined controls for the 'eb. (imilar to user defined windows controls but these are used for 'eb. Conso"e .%%"i&ation< new kind of application in 4isual (tudio .NET. They are command line based applications.

Win,ows $ervi&e< These run continuously regardless of the user interaction. They are designed for special purpose and once written, will keep running and come to an end only when the system is shut down. 2ther< This template is to de!elop other kinds of applications like enterprise applications, database applications etc.

$o"ution E0%"orer Win,ow The (olution Explorer window gi!es an o!er!iew of the solution we are working with and lists all the files in the project. n image of the (olution Explorer window is shown below.

$erver E0%"orer Win,ow The (er!er Explorer window is a great tool that pro!ides 8drag and drop8 feature and helps us work with databases in an easy graphical en!ironment. "or example, if we drag and drop a database table onto a form, 4B .NET automatically creates connection and command objects that are needed to access that table. The image below displays (er!er Explorer window.

1nte""isense Intellisense is what that is responsible for the boxes that open as we type the code. Intelli(ense pro!ides a list of options that make language references easily accessible and helps us to find the information we need. They also complete the typing for us. The image below displays that.

Co,e Designer Win,ow 2ode *esigners like the image below allows us to edit and write code. This is the window that opens when we double9click on a form or any control. This is the place where we write all the code for the application. Notice the two drop9down list boxes at the top of the code window in the image below. The left box allows us to select the object&s code we are working with and the right box allows us to select the part of code that we want to work. lso notice the 8K8 and 898 boxes in the code designer. Bou can use those boxes to display code 4isual Basic .NET already created, like, 'indows "orms *esigner generated code, etc.

+ro% erties Win,ow The properties window allows us to set properties for !arious objects at design time. "or example, if you want to change the font, font siEe, backcolor, name, text that appears on a button, textbox etc, you can do that in this window. Below is the image of properties window. Bou can !iew the properties window by selecting4iew9I1roperties 'indow from the main menu or by pressing "R on the keyboard.

D'nami& @e"% Win,ow The dynamic help window displays help which looks up for things automatically. "or example, if you want to get help with a form, select the form and select +elp9 I*ynamic +elp from the main menu. *oing that displays all the information relating to forms. The image below displays that. Bou can get help relating to anything with this feature. (ay, if you want to know more about the form, select the form and select *ynamic +elp from the +elp menu. *oing that displays information about the form as shown in the image below..

Comman, Win,ow The command window in the image below is a useful window. >sing this window we can add new item to the project, add new project and so on. Bou can !iew the command window by selecting 4iew9I)ther 'indows9I2ommand 'indow from the main menu. The command window in the image displays all possible commands with "ile.

Task List Win,ow The task list window displays all the tasks that 4B .NET assumes we still ha!e to finish. Bou can !iew the task list window by selecting 4iew9I(how tasks9I ll or 4iew9 I)ther 'indows9ITask /ist from the main menu. The image below shows that. s you can see from the image, the task list displayed 8TextBox# not declared8, 8=ichTextBox# not declared8. The reason for that message is, there were no controls on the form and attempts where made to write code for a textbox and a richtextbox. Task list also displays syntax errors and other errors you normally encounter during coding

C"ass View Win,ow The class !iew window like the image below is the window that presents solutions and projects in terms of the classes they contain and the members of these classes. >sing the class !iew window also helps us to find a member of a class that we want to work with. s you can notice from the image, the class !iew window displayed all the methods and e!ents for the controls which were a!ailable on the form.

2ut%ut Win,ow The output window as you can see in the image below displays the results of building and running applications.

2#3e&t E0%"orer Win,ow The object explorer window allows us to !iew all the members of an object at once. It lists all the objects in our code and gi!es us access to them. The image below displays an object explorer window. Bou can !iew the object explorer window by selecting 4iew9I)ther 'indows9I )bject Browser from the main menu.

Too"#o0 Win,ow The toolbox window is the window that gi!es us access to all controls, components, etc. s you can see from the image below, the toolbox uses tabs to di!ide it&s contents into categories 0*ata, 2omponents, 'indows "orms and @eneral3. The *ata tab displays tools for creating datasets and making data connections, the 'indows "orms tab displays tools for adding controls to forms, the @eneral tab is left empty by default, the 2lipboard =ing tab displays recent items stored in the clipboard and allows us to select from them.

Win,ows Forms
In 4isual Basic its these "orms with which we work. They are the base on which we build, de!elop all our user interface and they come with a rich set of classes. "orms allow us to work !isually with controls and other items from the toolbox. In 4B .NET forms are based on the (ystem.'indows."orms namespace and the form class is (ystem.'indows."orms."orm. The form class is based on the 2ontrol class which allows it to share many properties and methods with other controls. 'hen we open a new project in 4isual Basic the dialogue box that appears first is the one which looks like the image below. (ince we are working with 'indows pplications 0"orms3 you need to select 'indows pplication and click )[.

)nce you click )[ a new "orm opens with the title, "orm#, towards the top9left side of the form and maximiEe, minimiEe and close buttons towards the top right of the form. The whole form is surrounded with a border. The main area of the form in which we work is called the 2lient rea. It&s in this client area we design the user interface lea!ing all the code to the code behind file. "orms also support e!ents which let&s the form know that something happened with the form, for example, when we double9click on the form, the "orm load e!ent occurs. 4B .NET also supports forms to be inherited. Image of a 'indows "orm.

Typically the "orm looks like this in 2ode which is handled by the "ramework. 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 1ublic (ub New03 -yBase.New03 &This call is re6uired by the 'indows "orm *esigner. InitialiEe2omponent03 & dd any initialiEation after the InitialiEe2omponent03 call End (ub &"orm o!errides dispose to clean up the component list. 1rotected )!erloads )!errides (ub *ispose0By4al disposing s Boolean3 If disposing Then If Not 0components Is Nothing3 Then components.*ispose03 End If End If -yBase.*ispose0disposing3 End (ub &=e6uired by the 'indows "orm *esigner 1ri!ate components s (ystem.2omponent-odel.I2ontainer &N)TE< The following procedure is re6uired by the 'indows "orm *esigner &It can be modified using the 'indows "orm *esigner. &*o not modify it using the code editor. W(ystem.*iagnostics.*ebugger(tepThrough03I 1ri!ate (ub InitialiEe2omponent03 & &"orm# & -e. uto(caleBase(iEe J New (ystem.*rawing.(iEe0F, #A3 -e.2lient(iEe J New (ystem.*rawing.(iEe0R$?, R$A3 -e.Name J 8"orm#8 -e.Text J 8"orm#8

End (ub ;End =egion 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3 +andles -yBase./oad End (ub End 2lass Win,ows Form +ro%erties Below are the properties of a 'indows "orm. 1roperties displayed below are categoriEed as seen in the properties window.

5ppearance >roperties Description Bac?Co#or Bac?ground mage <ets3Sets the bac?ground co#or $or the $orm <et3Sets the bac?ground image in the $orm <ets3Sets the cursor to be disp#ayed @hen the user mo%es the mouse o%er the $orm <ets3Sets the $ont $or the $orm <ets3Sets the $oreground co#or o$ the $orm <ets3Sets the border sty#e o$ the $orm <ets3Sets the %a#ue indicating i$ the a#ignment o$ the contro#Cs e#ements is re%ersed to support right-to-#e$t $onts <ets3Sets the te-t associated @ith this $orm Description

Cursor

Aont AoreCo#or AormBorderSty#e

BightTo&e$t

Te-t Beha%ior >roperties

5##o@Drop

ndicates i$ the $orm can accept data that the user drags and drops into it <ets3Sets the shortcut menu $or the $orm <ets3Sets a %a#ue indicating i$ the $orm is enab#ed <ets3Sets the state o$ an nput 2ethod ,ditor Description <ets the data bindings $or a contro# <ets3Sets an ob*ect that contains data about a contro# Description <ets3Sets name $or the $orm ndicates @hether or not to dra@ the positioning grid Determines the size o$ the positioning grid <ets3Sets @hether the $orm is #oc?ed ndicates i$ the contro#s shou#d snap to the positioning grid Description ndicates i$ the $orm ad*usts its size to $it the height o$ the $ont used on the $orm and sca#es its contro#s ndicates i$ the $orm imp#ements autoscro##ing

Conte-t2enu ,nab#ed me2ode Data >roperties DataBindings

Tag

Design >roperties (ame Dra@<rid <ridSize &oc?ed

SnapTo<rid

&ayout >roperties

5utoSca#e

5utoScro##

5utoScro##2argin 5utoScro##2inSize Doc?>adding

The margin around contro#s during auto scro## The minimum #ogica# size $or the auto scro## region Determines the size o$ the border $or doc?ed contro#s <ets3Sets the co-ordinates o$ the upper-#e$t corner o$ the $orm The ma-imum size the $orm can be resized to The ma-imum size the $orm can be resized to <ets3Sets size o$ the $orm in pi-e#s <ets3Sets the starting position o$ the $orm at run time <ets3Sets the $ormCs @indo@ state Description <ets3Sets the button on the $orm that is pressed @hen the user uses the enter ?ey ndicates the button contro# that is pressed @hen the user presses the ,SC ?ey Determines @hether ?eyboard contro#s on the $orm are registered @ith the $orm ndicates the current #oca#izab#e #anguage Determines i$ #oca#izab#e code @i## be generated $or this ob*ect Description

&ocation

2a-imumSize 2inimumSize Size

Start>osition

Dindo@State 2isc >roperties

5cceptButton

Cance#Button

Eey>re%ie@

&anguage

&oca#izab#e

Dindo@ Sty#e

>roperties <ets3Sets a %a#ue indicating i$ a contro# bo- is disp#ayed Determines @hether a $orm has a he#p button on the caption bar <ets3Sets the icon $or the $orm <ets3Sets a %a#ue indicating i$ the $orm is a container $or 2D chi#d $orms <ets3Sets a %a#ue indicating i$ the ma-imize button is disp#ayed in the caption bar o$ the $orm <ets3Sets the 2ain2enu that is disp#ayed in the $orm <ets3Sets a %a#ue indicating i$ the ma-imize button is disp#ayed in the caption bar o$ the $orm Determines ho@ opa9ue or transparent the $orm is <ets3Sets a %a#ue indicating i$ the $orm is disp#ayed in the Dindo@s tas?bar Determines @hen the size grip @i## be disp#ayed $or the $orm <ets3Sets a %a#ue indicating i$ the $orm shou#d be disp#ayed as the topmost $orm o$ the app#ication 5 co#or @hich @i## appear transparent @hen painted on the $orm

Contro#Bo-

Fe#pButton

con

s2diContainer

2a-imizeBo-

2enu

2inimizeBo-

)pacity

Sho@ nTas?bar

Size<ripSty#e

Top2ost

TransparencyEey

Working with Forms 'ell, let&s now start working with "orms. 'hen you open a new form you can ha!e a look at the default properties of the form by selecting 4iew9I1roperties 'indow

or by pressing "R on the keyboard. The properties window opens with default properties set to form by the software.

Brie!"' on +ro%erties (Categori7e, * .%%earan&e ppearance section of the properties window allow us to make changes to the appearance of the form. 'ith the help of appearance properties we can ha!e a background color, background image for the entire form, set the border style for the form from a predefined list, change the cursor, set the font for the text on the form and so on. Behavior Notable Beha!ior property is the enabled property which lets us enable:disable the form by setting the property to True:"alse. La'out /ayout properties are all about the structure of the form. 'ith these properties we can set the location of the form, maximum siEe of the form, minimum siEe of the form, exact siEe of the form with the siEe property when designing. Note the property start position, this property lets you specify the location of the form where it should appear when you run the application which you can select from a predefined list. Win,ow $t'"e The notable property under this is the 2ontrolBox property which by default it is set to True. (etting the property to "alse makes the minimiEe, maximiEe and cancel buttons on the top right side of the form in!isible. Form Event The default e!ent of a form is the load e!ent which looks like this in code< 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles -yBase./oad

End (ub Bou can write code in the load e!ent of the form just like you write for all other controls. .n E0am%"e* Bou can run the "orm by selecting *ebug9I(tart from the main menu or by pressing "F on the keyboard. 'hen you run a blank form with no controls on it, nothing is displayed. It looks like the image below.

Now, add a TextBox and a Button to the form from the toolbox. The toolbox can be selected from 4iew9IToolBox on the main menu or by holding 2trlK ltK. on the keyboard. )nce adding the TextBox and Button is done, run the form. The output window displays a TextBox and a Button. 'hen you click the Button nothing happens. 'e need to write an e!ent for the Button stating something should happen when you click it. To do that get back to design !iew and double9click on the Button. *oing that opens an e!ent handler for the Button where you specify what should happen when you click the button. That looks like this in code.

1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles -yBase./oad End (ub 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick End (ub End 2lass 1lace the code TextBox#.TextJ8'elcome to "orms8 in the 2lick e!ent of the Button and run the application. 'hen you click the Button the output 8'elcome to "orms8 is displayed in the TextBox. lternati!ely, you can also use the -sgBox or -essageBox functions to display text when you click on the Button. To do that place a Button on the form and double9 click on that to open it&s e!ent. 'rite this line of code, -sgBox08'elcome to "orms83 or -essageBox.(how08'elcome to "orms83. It looks like this in code. 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick -sgBox08'elcome to "orms83 End (ub or 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick -essageBox.(how08'elcome to "orms83 End (ub 'hen you run the form and click the Button, a small message box displays, 8'elcome to "orms8. The image below displays that.

Working with Forms .,,ing a New Form to the +ro3e&t Bou can add a new form to the project with which you are working. To do that, select "ile9I dd New Item from the main menu which displays a window asking you what to add to the project. (elect 'indows "orm from the window and click )pen to add a new form to the project. lternati!ely, you can add a new form with the (olution Explorer. To add a new form with the (olution Explorer, right9click on the project name in (olution Explorer and (elect dd9I dd 'indows "orm. )nce you finish adding a new form, if you want the form which you added to be displayed when you run the application you need to make some changes. Bou need to set the new form as (tartup )bject. To do that, right9click on the project name in (olution Explorer window and select 1roperties which displays the 1roperty 1ages window. )n this window click the drop9down box which is labeled as (tartup )bject. *oing that displays all the forms a!ailable in the project. It looks like the image below.

(elect the form which you want to be displayed when you run the application and click pply. Now, when you run the application, the form you assigned as (tartup object will be displayed.

Working with 5u"ti%"e Forms /et&s see how we can work with more than one form:open a new form. (ay, for example, we want to open a new form 0"orm73 when a button in the current form 0"orm#3 is clicked. To do that, open a new project by selecting "ile9INew9I1roject9 I4isual Basic9I'indows pplication. This adds a form 0"orm#3 to the application. dd a new form 0"orm73 by selecting "ile9I dd New Item9I'indows "orm. lso, drag a button 0Button#3 onto "orm#. 'e want to open "orm7 when the button in "orm# is clicked. >nlike earlier !ersions of 4isual Basic, 4B .NET re6uires us to refer to "orm7 in "orm# in order to open it i.e creating an object of "orm7 in "orm#. The code for that looks like this< 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm *im other s New "orm703 &2reating a reference to "orm7

1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick other.(how03 End (ub Visua" 1nheritan&e with Forms s we know, Inheritance allows us to deri!e one class from another. 4B. NET allows us to inherit one form from another. /et&s see how we can inherit a new form from an existing form. (ay, we ha!e a form named "orm# with some controls on it and we want to inherit a new form from that form. To deri!e a new form from the existing one select 1roject9I dd Inherited "orm from the main menu. *oing that opens the dd New Item window. *ouble9click on the Inherited "orm Icon in the templates box to open the Inheritance 1icker. Inheritance 1icker window looks like the image below.

(elect "orm# in the picker and click )[. 2licking )[ adds a new form, "orm7, which is deri!ed from "orm#. E!erything on "orm7 including the title is copied from "orm#. The only difference between form# and form7 is, the controls on "orm7 come with a special icon at the upper left corner which indicates that the form is inherited and the controls are locked. The image below displays a Inherited "orm.

2wne, Forms 4isual Basic also allows us to create owned forms. n owned form is tied to the form that owns it. If you minimiEe the owner form, the owned form will also be minimiEed, if you close the owner form, the owned form will be closed and so on. )wned "orms are added to a form with the dd)wned"orm method and remo!ed with the =emo!e)wned"orm method. The following code demonstrates the creation of owned forms. *rag a Button from the toolbox onto the form 0form#3. 'hen you click the button, "orm# will make an object of the "orm class into an owned form and displays it. The code for that looks like this<

1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm *im )wned"orm# s New "orm03 1ri!ate (ub Button7Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button7.2lick -e. dd)wned"orm0)wned"orm#3 &adding an owned form to the current form )wned"orm#.show03 &displaying the owned form End (ub

The image below displays output from abo!e code.

1n%utBo0 Fun&tion InputBox function gets a string of text entered by the user. They are similar to the 5a!a(cript prompt windows that ask us to enter some text and performs some action after the )[ button is clicked. In 4isual Basic Input boxes let you display a prompt, read the text entered by the user and returns a string result. The following code demonstrates InputBox function. *rag a Button and TextBox control from the toolbox onto the form. 'hen you click the Button, InputBox asks to enter some text and after you click )[ it displays the text you entered in the TextBox. The image below displays output. 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick *im s s (tring J InputBox08Enter some text83 &storing the text entered in a string TextBox#.Text J s &displaying string in the textbox End (ub nchoring and *ocking 2ontrols

nchoring and *ocking is used to make controls co!er the whole client area of a form. .n&horing nchoring is used to resiEe controls dynamically with the form. If you are designing a form that the user can resiEe at run time then the controls on your form should resiEe and reposition properly. The nchor property defines an anchor position for the control. 'hen a control is anchored to a form and the form is resiEed, the control maintains the distance between the control and the anchor positions. .n&horing a &ontro" To anchor a control, first select the control. In the 1roperties window select nchor property. (electing that displays an editor that shows a cross. To set an anchor, click the top, left, right, or bottom section of the cross. By default controls are anchored to the top and left side. To clear a side of the control that has been anchored click that side of the cross. 'hen your run the form the control resiEes to remain positioned at the same distance from the edge of the form. The distance from the anchored edge always remains the same as the distance defined when the control is positioned during design time. The image below demonstrates that. Do&king 'hen you dock a control, it adheres to the edges of its container 0form3. To dock a control, select the *ock property of that control from the properties window. (electing the dock property opens up a small editor from which you can select to which side on the form should the control be docked. Do&king a &ontro" (elect the control that you want to dock. In the 1roperties window select *ock property. n editor is displayed that shows a series of boxes representing the edges and the center of the form. 2lick the button that represents the edge of the form where you want to dock the control. To fill the contents of the control&s form or container control, click the center box. The control is automatically resiEed to fit the boundaries of the docked edge.

Working with E0am%"e The following three images will demonstrate nchoring and *ocking. The image below is a form with a TextBox on it.

.n&horing The image below displays the TextBox anchored to top9right side of the form. "rom the image you can !iew the TextBox maintaining the same distance from the top and right sides of the form when the form is increased in siEe.

Do&king

The image below displays the TextBox docked towards the bottom of the form.

Win,ows Forms 2%a&it' beautiful feature of 'indows "orms is )pacity. The )pacity property is used to make a form transparent. To set this property set the )pacity property to a !alue between % 0complete transparency3 and #%% 0complete opacity3 in the properties window. The Image below demonstrates )pacity property. The form is set to an opacity !alue of YF.

Transparent forms are only supported in 'indows 7%%% or later. 'indows "orms will be completely opa6ue when run on older operating systems such as 'indows $X:$F regardless of the !alue set for the )pacity property. @an,"ing 5ouse Events in Forms 'e can handle mouse e!ents such as mouse pointer mo!ements in "orms. The mouse e!ents supported by 4B .NET are as follows< 5ouseDown< This e!ent happens when the mouse pointer is o!er the form:control and is pressed 5ouseEnter< This e!ent happens when the mouse pointer enters the form:control 5ouse6%< This e!ent happens when the mouse pointer is o!er the form:control and the mouse button is released 5ouseLeave< This e!ent happens when the mouse pointer lea!es the form:control 5ouse5ove< This e!ent happens when the mouse pointer is mo!ed o!er the form:control 5ouseWhee"< This e!ent happens when the mouse wheel mo!es while the form:control has focus 5ouse@over< This e!ent happens when the mouse pointer ho!ers o!er the form:control The properties of the -ouseE!ent rgs objects that can be passed to the mouse e!ent handler are as follows< Button< (pecifies that the mouse button was pressed C"i&ks< (pecifies number of times the mouse button is pressed and released 4< The .9coordinate of the mouse click << The B9coordinate of the mouse click De"ta< (pecifies a count of the number of detents 0rotation of mouse wheel3 the mouse wheel has rotated Working with an E0am%"e 'e will work with an example to check the mouse e!ents in a form. 'e will be working with -ouse*own, -ouseEnter and -ouse/ea!e e!ents in this example. *rag three TextBoxes 0TextBox#, TextBox7, TextBoxA3 onto the form. The idea here is to display the results of these e!ents in the TextBoxes. 2ode 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm &'indows "orm *esigner @enerated 2ode 1ri!ate (ub "orm#Q-ousedown0By4al sender s (ystem.)bject, By4al e s Q (ystem.'indows."orms.-ouseE!ent rgs3 +andles -yBase.-ouse*own

If e.Button J -ouseButtons./eft Then TextBox#.Text J 8-ouse down at8 K 2(tr0e..3 K 8 <8 K 2(tr0e.B3 &displaying the coordinates in TextBox# when the mouse is pressed on the form End If End (ub 1ri!ate (ub "orm#Q-ouseEnter0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -yBase.-ouseEnter TextBox7.Text J 8-ouse Entered8 &displaying 8mouse entered8 in TextBox7 when the mouse pointer enters the form End (ub 1ri!ate (ub "orm#Q-ouse/ea!e0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -yBase.-ouse/ea!e TextBoxA.Text J 8-ouse Exited8 &displaying 8mouse exited8 in TextboxA when the mouse pointer lea!es the form End (ub End 2lass The image below displays the output.

Bee% Fun&tion The Beep "unction in 4B.NET can be used to make the computer emit a beep. To see how this works, drag a Button onto the form and place the following code in it&s click e!ent< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick Beep03 End (ub 'hen you run the code and click the button your computer emits a beep. 5D1 .%%"i&ations -*I 0-ultiple *ocument Interface3 pplication is an application in which we can !iew and work with se!eral documents at once. Example of an -*I application is -icrosoft Excel. Excel allows us to work with se!eral documents at once. In contrast, (*I 0(ingle *ocument Interface3 applications are the applications which allows us to work with a single document at once. Example of a single document application is -icrosoft 'ord in which only one document is !isible at a time. 4isual Basic .NET pro!ides great support for creating and working with -*I applications. In general, -*I applications are mostly used by financial ser!ices organiEations where the user needs to work with se!eral documents at once. Creating 5D1 .%%"i&ations /et&s create an -*I application. )pen a new 'indows pplication in 4isual Basic .NET. The application will open with a default form, "orm#. dd another form, "orm7 to this application by right9clicking on the project name in (olution Explorer window and selecting dd9I dd 'indows "orm. Bou can add some controls to "orm7. "or this application we will make "rom# as the -*I parent window and "orm7 as -*I child window. -*I child forms are important for -*I pplications as users interact mostly through child forms. (elect "orm# and in it&s 1roperties 'indow under the 'indows (tyle section, set the property Is-di2ontainer to True. (etting it to true designates this form as an -*I container for the child windows. )nce you set that property to true the form changes it&s color. Now, from the toolbox drag a -ain-enu component onto "orm#. 'e will display child windows when a menu item is clicked. Name the top9le!el menu item to "ile with submenu items as New 2hild 'indow, rrange 2hild 'indows and Exit. The whole form should look like the image below.

'ith this application a new child window is displayed each time the New 2hild 'indow menu item is clicked, all child windows will be arranged when you click rrange 2hild 'indows menu item. To get the desired result, open the code designer window and paste the following code. 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm *im child"orm s Integer J % *im child"orms0F3 s "orm7 &declaring an array to store child windows &fi!e child windows 0"orm73 will be displayed ;=egion 8 'indows "orm *esigner generated code 8 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e Q s (ystem.E!ent rgs3 +andles -yBase./oad End (ub 1ri!ate (ub -enuItem7Q2lick0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles -enuItem7.2lick child"orm KJ # child"orms0child"orm3 J New "orm703 child"orms0child"orm3.Text J 82hild"orm8 L (tr0child"orm3 &setting title for child windows and incrementing the number with an array child"orms0child"orm3.-di1arent J -e child"orms0child"orm3.(how03 End (ub 1ri!ate (ub -enuItemAQ2lick0By4al sender s (ystem.)bject,Q

By4al e s (ystem.E!ent rgs3 +andles -enuItemA.2lick -e./ayout-di0-di/ayout.2ascade3 &arranging child windows on the parent form with predefined /ayout-di method &*ifferent layouts a!ailable are, rrangeIcons, 2ascade, Tile+oriEontal, Tile4ertical End (ub 1ri!ate (ub -enuItemRQ2lick0By4al sender s (ystem.)bject, By4alQ e s (ystem.E!ent rgs3 +andles -enuItemR.2lick -e.2lose03 &closing the application End (ub End 2lass 'hen you run the application and click 8New 2hild 'indow8 menu item, a new child window is displayed. "i!e child windows will be displayed as we declared an array of fi!e in code. The image below displays the output.

'hen you click on 8 rrange 2hild 'indows8 menu item, all child windows are arranged. It looks like the image below.

Format 5enu in V$ .NET The "ormat -enu a!ailable in 4isual (tudio .NET I*E allows us to align, layer and lock controls on a form. The "ormat menu pro!ides many options for arranging controls. The "ormat -enu is shown in the image below.

'hen using "ormat menu for arranging controls, we need to select the controls in such a way that the last control selected is the primary control to which other controls are

aligned. The primary control has dark siEe handles and all other controls ha!e light siEe handles. The different options that are a!ailable under the "ormat menu are listed below. ."ign< ligns all controls with respect to the primary control 5ake $ame $i7e< =esiEes multiple controls on a form @ori7onta" $%a&ing< Increases horiEontal spacing between controls Verti&a" $%a&ing< Increases !ertical spacing between controls Center in Form< 2enters the controls on form 2r,er< /ayers controls on form Lo&k Contro"s< /ocks all controls on form ."igning mu"ti%"e &ontro"s on a Form /et&s work with an example. )pen a new form and drag some controls onto it from the toolbox. (elect the controls you want to align. The last control you select is the primary control to which all other controls align. )n the "ormat menu point to align and then click any of the se!en options a!ailable. The image below displays the controls after selection. "rom the image notice the 2heckBox control with dark handles. That&s the primary control.

The image below displays controls that are aligned after selecting the option /efts under lign from the "ormat menu. ll the controls are left9aligned.

5ake $ame $i7e The -ake (ame (iEe option under "ormat menu pro!ides four options using which we can make all the controls same in siEe, width or height. The image below displays controls with the option width that makes all the controls same in width as the primary control.

Lo&king Contro"s To lock all controls so that they cannot be mo!ed accidentally, select "ormat menu and click lock controls. The image below displays that.

De#ugging VB .NET .%%"i&ations In this section we will focus on some common issues while debugging our applications and we will take a close look at the *ebug -enu 4isual (tudio .NET pro!ides us. Errors in programming are ine!itable. E!eryone of us introduce errors while coding. Errors are normally referred to as bugs. The process of going through the code to identify the cause of errors and fixing them is called *ebugging. T'%es o! Errors $'nta0 Errors The most common type of errors, syntax errors, occur when the compiler cannot compile the code. (yntax errors occur when keywords are typed incorrectly or an incorrect construct is parsed. The image below displays a syntax error in the code editor.

Fi0ing $'nta0 Errors 4( .NET allows us to easily identify syntax errors. 'hen we build the project, syntax errors are automatically detected and underlined in code. Errors that are detected are also added to the Task /ist window. Bou can double9click any error in the Task /ist window and the cursor will immediately highlight that error in the code window. In most cases this is sufficient to correct the errors. Run-Time Errors =un9Time errors occur when the application attempts to perform a task that is not allowed. This includes tasks that are impossible to carry out, such as di!iding by Eero, etc. 'hen a run9time error occurs, an exception describing the error is thrown. Exceptions are special classes that are used to communicate error states between different parts of the application. To handle run9time errors, we need to write code 0normally, using Try...2atch..."inally3 so that they don&t halt execution of our application. The image below shows a run time error.

Logi&a" Errors /ogical Errors occur when the application compiles and executes correctly, but does not output the desired results. These are the most difficult types of errors to trace because there might be no indications about the source of the error. The only way to detect and correct logical errors is by feeding test data into the application and analyEing the results. The image below describes a common scenario where logical errors occur. ssume, the image abo!e performs some calculations for the purpose of taxation. It multiplies three numbers. "irst number is the hourly wage an employee gets, second number is the number of weeks in a year and third number is the number of hours a week 0R% hrs fulltime3 the employee works. 'hat happens here is, the code still executes correctly and produces the output but the produced output is not the desired result as the third number in code is R%% instead of R%. The output shown is 7R$ grand instead of 7R grand. This is a simple scenario where logical errors occur.

De#ugging VB .NET .%%"i&ations This section focuses on Breakpoints and the *ebug -enu found in 4isual (tudio .NET, the items within it and their use. Break 5o,e Break -ode allows us to halt code execution and execute code one line at a time. In break mode we can examine the !alues of application !ariables and properties. 4isual (tudio .NET enters break mode under any of the following circumstances< 9 'hen we choose (tep Into, (tep )!er or (tep out from the *ebug menu 9 Execution reaches a line that contains an enabled breakpoint 9 Execution reaches a (top statement 9 n unhandled exception is thrown

The image below shows the code designer window in Break -ode.

)nce in Break mode we can use the debugging tools to examine our code. The image below shows the features on *ebug menu.

De#ug 5enu 1tems !rom the a#ove image summari7e,< Win,ows< )pens a submenu that allows us to choose a debugging window to !iew. $tart=Continue< =uns the application in debug mode. In Break mode, this option continues program execution.

Break .""* 2auses program execution to halt and enter break mode at the current program line. Bou can choose continue to resume execution. $to% De#ugging< (tops the debugger and return to design mode in 4isual (tudio. Deta&h .""* *etaches the debugger from all processes it is debugging. This closes the debugger without halting program execution. Restart* Terminates and restarts application execution. pply 2ode 2hanges< 'orks for 2:2KK programming. *oesn&t work for 4B and 2;. +ro&esses* *isplays the processes window. E0&e%tions* *isplays the exception window. $te% 1nto< =uns the next executable line of code. If the next line calls a method, (tep Into stops at the beginning of that method. $te% 2ver< =uns the next executable line of code. If the next line calls a method, (tep )!er executes that method and stops at the next line within the current method. Fui&kWat&h< *isplays the Cuick'atch window. New Break%oint< *isplays the New Breakpoint 'indow. C"ear ."" Break%oints< =emo!es all breakpoints from the application. Disa#"e ."" Break%oints< *isables all breakpoints, but does not delete them. There are some more debugging functions that can be accessible by right9clicking on an element in the code window and choosing a function from the pop9up menu. The image below displays those functions and summariEes them.

1nsert Break%oint< Inserts a breakpoint at the selected line. New Break%oint< *isplays the new Breakpoint window. Identical to the *ebug menu item of the same name. .,, Wat&h< dds the selected expression to the watch window. Fui&kWat&h< *isplays the Cuick'atch window.

$how Ne0t $tatement< +ighlights the next statement to be executed. Run To Cursor< =uns program execution to the selected line. $et Ne0t $tatement< *esignates the selected line as the next line of code to be executed. The selected line should be in the current procedure. Break%oints 'e can insert breakpoints at lines of code that will always cause the application to break in the debugger. Breakpoints are used to set lines of code that will halt code execution. There are four types of breakpoints as discussed below< Fun&tion #reak%oints< 2auses the application to enter Break mode when the specified location in the function is reached. Fi"e #reak%oints< 2auses the application to enter Break mode when the specified location in the file is reached. .,,ress #reak%oints< 2auses the application to enter Break mode when the specified memory address is reached Data #reak%oints< 2auses the application to enter Break mode when the !alue of a !ariable changes. Not a!ailable in 4B and 2;. The image below displays the code designer when a breakpoint is inserted.

'hen setting breakpoints with the New Breakpoint window we can attach conditions that determine whether or not execution halts when the breakpoint is reached. 1ressing the 2ondition button displays the Breakpoint 2ondition window which allows us to designate an expression and causes the breakpoint to be acti!e only if the breakpoint is true or if the expression changes. Break%oints Win,ow

The Breakpoints 'indow lists all of the breakpoints in the project, like, where the breakpoint is located and any conditions attached to it. 'e can disable a breakpoint by clearing the check box next to it. The button in the Breakpoints window allows us to create a new breakpoint, delete a breakpoint or clear or disable all breakpoints. The 2olumns drop9down menu allows us to choose additional columns of information about the breakpoints. The image below displays a breakpoints window.

Removing an, Disa#"ing Break%oints 'e can remo!e a breakpoint by clicking on the circle like display towards the left side of the code window where the breakpoint is inserted. To disable a breakpoint, right9 click the break 6ser 1nter!a&e Design +rin&i%"es >ser Interface is a !ery important factor when we design our application 0project3. >ser interface pro!ides a mechanism for end users to interact with the application. End users are called target audience. *esigning a good user interface which is easy to use and understand is crucial for a successful application. If you already know the target audience for whom you are de!eloping the application then designing becomes simple as you will already be familiar with their corporate colors and likes. Target audience, for example, can be the employee&s of a firm for whom you will design the application. well designed user interface makes it easy and simple for the target audience to understand and use. )n the other hand, a poorly designed user interface will be hard to understand and use and can lead to distraction and frustration. @ood user interface is possible if it is designed keeping in mind the following four principles< #3 (implicity 73 1ositioning of 2ontrols A3 2onsistency R3 esthetics

The image below is an example of a good user interface design.

The abo!e said four principles explained<

$im%"i&it' (implicity is a key factor when designing a user interface. If a user interface looks crowded with controls then learning and using that application will be hard. (implicity means, the user interface should allow the user to complete all the re6uired tasks by the program 6uickly and easily. lso, program flow and execution should be kept on mind while designing. Try to a!oid use of flashy and unnecessary images that distract the user. The simpler the user interface, the more friendly and easy it will be. +ositioning o! Contro"s 1ositioning of controls should reflect their importance. (ay, for example, if you are designing an application that has a data9entry form with textboxes, buttons, radio buttons, etc. The controls should be positioned in such a way that they are easy to located and matches the program flow. /ike, a submit button should be placed at the bottom of the form so that when the user enters all the data he can click it straight away. The image abo!e is a perfect example of positioning of controls.

Consisten&' The user interface should ha!e a consistent look through out the application. The key to consistency lies during the design process. Before de!eloping an application, we need to plan and decide a consistent !isual scheme for the application that will be followed throughout. >sing of particular fonts for special purposes, using of colors for headings, use of images, etc are all part of consistency. .estheti&s n application should project an in!iting and pleasant user interface. The following should be considered for that. Co"or >se of color is one way to make the user interface attracti!e to the user. The color which you select for text and back9ground should be appealing. 2are should be taken to a!oid gaudy colors that are disturbing to the eye, for example, black text on a red back9 ground. Fonts The fonts which you use for text should also be selected with care. (imple, easy9 to9read fonts like 4erdana, Times New =oman should be used. Try to a!oid bold, strikeout text in most parts of the application. >se of bold, italics and other formatting should be limited to important text or headings. 1mages Images add !isual interest to the application. (imple, plain images should be used where!er appropriate. !oid using flashing images and images that are not necessary but are used only for show off. $ha%es an, Trans%aren&' .NET "ramework pro!ides tools that allow us to create forms and controls with different le!els of opacity. part from using traditional shapes like rectangles, etc, these tools also allow us to draw our own shapes which can pro!ide some !ery powerful !isual effects. >ser drawn shapes should be used only if the application re6uires it and care should be taken that the shapes which are drawn do not disturb the eye. The image below is an example of a poorly designed user interface.

Contro"s control is an object that can be drawn on to the "orm to enable or enhance user interaction with the application. Examples of these controls, TextBoxes, Buttons, /abels, =adio Buttons, etc. ll these 'indows 2ontrols are based on the 2ontrol class, the base class for all controls. 4isual Basic allows us to work with controls in two ways< at design time and at runtime. 'orking with controls at design time means, controls are !isible to us and we can work with them by dragging and dropping them from the Toolbox and setting their properties in the properties window. 'orking at runtime means, controls are not !isible while designing, are created and assigned properties in code and are !isible only when the application is executed. There are many new controls added in 4isual Basic .NET and we will be working with some of the most popular controls in this section. Bou can select the controls from the menu towards the left9hand side of this page. Notable properties of most of these 'indows 2ontrols which are based on the 2ontrol class itself are summariEed in the table below. Bou can always find the properties of the control with which you are working by pressing "R on the keyboard or by selecting 4iew9I1roperties 'indow from the main menu.

The Contro" C"ass The 2ontrol class is in the (ystem.'indows."orms namespace. It is a base class for the 'indows 2ontrols. The class hierarchy is shown below. )bject -arshalBy=ef)bject 2omponent 2ontrol ButtonBase, Etc, Etc Button, Etc, Etc -ain class is the )bject class from which -arshalBy=ef)bject class is deri!ed and the 2omponent class is deri!ed from the -arshalBy=ef)bject class and so on. The properties of the 2ontrol object are summariEed below. 1roperties are alphabetical as seen in the properties window.

>roperty

Description
ndicates i$ the $orm can accept data that the user drags and drops into it

5##o@Drop

5nchor

<ets3Sets @hich edges o$ the contro# are anchored

Bac?Co#or

<ets3Sets the bac?ground co#or $or the contro#

Bac?ground mage

<ets3Sets the bac?ground image in the contro#

Bottom

<ets the distance be@teen the bottom o$ the contro# and the top o$ its container c#ient area

Bounds

<ets3Sets the contro#s bounding rectang#e

CanAocus

Beturns a %a#ue speci$ying i$ the contro# can recie%e $ocus

CanSe#ect

Beturns a %a#ue speci$ying i$ the contro# can be se#ected

Capture

<ets3Sets a %a#ue speci$ying i$ the contro# has captured the mouse

Causes'a#idation

<ets3Sets a %a#ue spec$ying i$ the contro# causes %a#idation $or a## contro#s that re9uire %a#idation

ContainsAocus

Beturns a %a#ue speci$ying i$ the contro# has the input $ocus

Conte-t2enu

<ets3Sets the shortcut menu $or the contro#

Contro#s

<ets3Sets the co##ection o$ contro#s contained @ithin the contro#

Cursor

<ets3Sets the cursor to be disp#ayed @hen the user mo%es the mouse o%er the $orm

DataBindings

<ets the data bindings $or the contro#

Doc?

<ets3Sets @hich edge o$ the parent a contro# is doc?ed to

,nab#ed

<ets3Sets a %a#ue indicating i$ the contro# is enab#ed

Aocused

Beturns a %a#ue speci$ying i$ the contro# has input $ocus

Aont

<ets3Sets the $ont $or the contro#

AoreCo#or

<ets3Sets the $oreground co#or o$ the contro#

FasChi#dren

Beturns a %a#ue speci$ying i$ the contro# contains chi#d contro#s

Feight

<ets3Sets the height o$ the contro#

&e$t

<ets3Sets the --coordinates o$ a contro#Cs #e$t edge in pi-e#s

&ocation

<ets3Sets the co-ordinates o$ the upper-#e$t corner o$ the contro#

(ame

<ets3Sets name $or the contro#

>arent

<ets3Sets the contro#Cs parent container

Bight

Beturns the distance bet@een the right edge o$ the contro# and the #e$t edge o$ itCs container

BightTo&e$t

<ets3Sets the %a#ue indicating i$ the a#ignment o$ the contro#Cs e#ements is re%ersed to support right-to-#e$t $onts

Size

<ets3Sets size o$ the contro# in pi-e#s

Tab nde-

<ets3Sets the tab order o$ this contro# in its container

TabStop

<ets3Sets a %a#ue speci$ying i$ the user can tab to this contro# @ith the tab ?ey

Tag

<ets3Sets an ob*ect that contains data about the contro#

Te-t

<ets3Sets the te-t $or this contro#

Top

<ets3Sets the top coordinates o$ the contro#

'isib#e

<ets3Sets a %a#ue speci$ying i$ the contro# is %isib#e

Didth

<ets3Sets the @idth o$ the contro#

Button Contro" )ne of the most popular control in 4isual Basic is the Button 2ontrol 0pre!iously 2ommand 2ontrol3. They are the controls which we click and release to perform some action. Buttons are used mostly for handling e!ents in code, say, for sending data entered in the form to the database and so on. The default e!ent of the Button is the 2lick e!ent and the Button class is based on the ButtonBase class which is based on the 2ontrol class. Button Event The default e!ent of the Button is the 2lick e!ent. 'hen a Button is clicked it responds with the 2lick E!ent. The 2lick e!ent of Button looks like this in code< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick &Bou place the code here to perform action when Button is clicked End (ub Working with Buttons 'ell, it&s time to work with Buttons. *rag a Button from the toolbox onto the "orm. The default text on the Button is Button#. 2lick on Button# and select it&s properties by pressing "R on the keyboard or by selecting

4iew9I1roperties 'indow from the main menu. That displays the 1roperties for Button#. 1m%ortant +ro%erties o! Button9 !rom +ro%erties Win,ow< .%%earan&e ppearance section of the properties window allows us to make changes to the appearance of the Button. 'ith the help of Back2olor and Background Image properties we can set a background color and a background image to the button. 'e set the font color and font style for the text that appears on button with "ore2olor and the "ont property. 'e change the appearance style of the button with the "lat(tyle property. 'e can change the text that appears on button with the Text property and with the Text lign property we can set where on the button the text should appear from a predefined set of options. Behavior Notable Beha!ior properties of the Button are the Enabled and 4isible properties. The Enabled property is set to True by default which makes the button enabled and setting it&s property to "alse makes the button *isabled. 'ith the 4isible property we can make the Button 4isible or In!isible. The default !alue is set to True and to make the button In!isible set it&s property to "alse. La'out /ayout properties are about the look of the Button. Note the *ock property here. control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container. The default !alue is set to none. If you want to dock the control towards the left, right, top, bottom and center you can do that by selecting from the button like image this property displays. 'ith the /ocation property you can change the location of the button. 'ith the (iEe property you can set the siEe of the button. part from the *ock property you can set it&s siEe and location by mo!ing and stretching the Button on the form itself. Creating a Button in Co,e Below is the code to create a button. 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andlesQ -yBase./oad *im Button# as New Button03 &declaring the button, Button# Button#.TextJ82reating a Button8

&setting the text to be displayed on the Button Button#./ocationJNew 1oint0#%%,F%3 &setting the location for the Button where it should be created Button#.(iEeJNew (iEe0YF,7A3 &setting the siEe of the Button -e.2ontrols. dd0Button#3 &adding the Button that is created to the form &the -e keyword is used to refer to the current object, in this case the "orm End (ub End 2lass

Te0tBo0 Contro" 'indows users should be familiar with textboxes. This control looks like a box and accepts input from the user. The TextBox is based on the TextBoxBase class which is based on the 2ontrol class. TextBoxes are used to accept input from the user or used to display text. By default we can enter up to 7%RX characters in a TextBox but if the -ultiline property is set to True we can enter up to A7[B of text $ome Nota#"e +ro%erties* (ome important properties in the Beha!ior section of the 1roperties 'indow for TextBoxes. Enabled< *efault !alue is True. To disable, set the property to "alse. -ultiline< (etting this property to True makes the TextBox multiline which allows to accept multiple lines of text. *efault !alue is "alse. 1assword2har< >sed to set the password character. The text displayed in the TextBox will be the character set by the user. (ay, if you enter V, the text that is entered in the TextBox is displayed as V. =ead)nly< -akes this TextBox readonly. It doesn&t allow to enter any text. 4isible< *efault !alue is True. To hide it set the property to "alse. 1m%ortant %ro%erties in the .%%earan&e se&tion Text lign< llows to align the text from three possible options. The default !alue is left and you can set the alignment of text to right or center. (crollbars< llows to add a scrollbar to a Textbox. 4ery useful when the TextBox is multiline. Bou ha!e four options with this property. )ptions are are None, +oriEontal, 4ertical and Both. *epending on the siEe of the TextBox anyone of those can be used.

Te0tBo0 Event The default e!ent of the TextBox is the Text2hanged E!ent which looks like this in code< 1ri!ate (ub TextBox#QText2hanged0By4al sender s (ystem.)bject, By4al e s Q (ystem.E!ent rgs3 +andles TextBox#.Text2hanged End (ub Working With Te0tBo0es /ets work with some examples to understand TextBoxes. *rag two TextBoxes 0TextBox#, TextBox73 and a Button 0Button#3 from the toolbox. 2ode to *isplay some text in the TextBox 'e want to display some text, say, 8'elcome to TextBoxes8, in TextBox# when the Button is clicked. The code looks like this< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick TextBox#.Text J 8'elcome to TextBoxes8 End (ub Co,e to Work with +assWor, Chara&ter (et the 1assword2har property of TextBox7 to V. (etting that will make the text entered in TextBox7 to be displayed as V. 'e want to display what is entered in TextBox7 in TextBox#. The code for that looks like this< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick TextBox#.Text J TextBox7.Text End (ub 'hen you run the program and enter some text in TextBox7, text will be displayed as V. 'hen you click the Button, the text you entered in TextBox7 will be displayed as plain text in TextBox#. Co,e to Va"i,ate 6ser 1n%ut

'e can make sure that a TextBox can accept only characters or numbers which can restrict accidental operations. "or example, adding two numbers of the form 7YK75 cannot return anything. To a!oid such kind of operations we use the [ey1ress e!ent of the TextBox. 2ode that allows you to enter only double digits in a TextBox looks like this< 1ri!ate (ub TextBox#Q[ey1ress0By4al sender s )bject,By4al e sQ (ystem.'indows."orms.[ey1ressE!ent rgs3 +andles TextBox#.[ey1ress If0e.[ey2har W 8#%8 )r e.[ey2har I 8#%%83 Then -essageBox.(how08Enter *ouble *igits83 End If End (ub

Creating a Te0tBo0 in Co,e 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -yBase./oad *im TextBox# as New TextBox03 TextBox#.TextJ8+ello -ate8 TextBox#./ocationJNew 1oint0#%%,F%3 TextBox#.(iEeJNew (iEe0YF,7A3 -e.2ontrols. dd0TextBox#3 End (ub End 2lass Ri&hTe0tBo0 =ichTextBoxes are similar to TextBoxes but they pro!ide some ad!anced features o!er the standard TextBox. =ichTextBox allows formatting the text, say adding colors, displaying particular font types and so on. The =ichTextBox, like the TextBox is based on the TextBoxBase class which is based on the 2ontrol class. These =ichTextBoxes came into existence because many word processors these days allow us to sa!e text in a rich text format. 'ith =ichTextBoxes we can also create our own word processors. 'e ha!e two options when accessing text in a =ichTextBox, text and rtf 0rich text format3. Text holds text in normal text and rtf holds text in rich text format. Ri&hTe0tBo0 Event

The default e!ent of =ichtextBox is the Text2hanged e!ent which looks like this in code< 1ri!ate (ub =ichTextBox#QText2hanged0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles =ichTextBox#.Text2hanged End (ub Co,e $am%"es 2ode for creating bold and italic text in a =ichTextBox *rag a =ichTextBox 0=ichTextBox#3 and a Button 0Button#3 onto the form. Enter some text in =ichTextBox#, say, 8'e are working with =ichTextBoxes8. 1aste the following code in the click e!ent of Button#. The following code will search for text we mention in code and sets it to be displayed as Bold or Italic based on what text is searched for. 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick =ichTextBox#.(election(tart J =ichTextBox#."ind08are83 &using the "ind method to find the text 8are8 and setting it&s &return property to (election(tart which selects the text to format *im ifont s New "ont0=ichTextBox#."ont, "ont(tyle.Italic3 &creating a new font object to set the font style =ichTextBox#.(election"ont J ifont &assigning the !alue selected from the =ichTextBox the font style =ichTextBox#.(election(tart J =ichTextBox#."ind08working83 *im bfont s New "ont0=ichTextBox#."ont, "ont(tyle.Bold3 =ichTextBox#.(election"ont J bfont End (ub 'hen you run the abo!e code and click Button#, the text 8are8 is displayed in Italic and the text 8working8 is displayed in Bold font. The image below displays the output. Co,e !or $etting the Co"or o! Te0t /ets work with pre!ious example. 2ode for setting the color for particular text looks like this< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick

=ichTextBox#.(election(tart J =ichTextBox#."ind08are83 &using the "ind method to find the text 8are8 and setting it&s return &property to (election(tart which selects the text =ichTextBox#.(election2olor J 2olor.Blue &setting the color for the selected text with (election2olor property =ichTextBox#.(election(tart J =ichTextBox#."ind08working83 =ichTextBox#.(election2olor J 2olor.Bellow End (ub The output when the Button is 2licked is the text 8are8 being displayed in Blue and the text 8working8 in yellow as shown in the image below.

Co,e !or $aving Fi"es to RTF *rag two =ichTextBoxes and two Buttons 0(a!e, /oad3 onto the form. 'hen you enter some text in =ichTextBox# and click on (a!e button, the text from =ichTextBox# is sa!ed into a rtf 0rich text format3 file. 'hen you click on /oad button the text from the rtf file is displayed into =ichTextBox7. The code for that looks like this<

1ri!ate (ub (a!eQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles (a!e.2lick =ichTextBox#.(a!e"ile08hello.rtf83 &using (a!e"ile method to sa!e text in a rich text box to hard disk End (ub 1ri!ate (ub /oadQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles /oad.2lick =ichTextBox7./oad"ile08hello.rtf83 &using /oad"ile method to read the sa!ed file End (ub

The files which we create using the (a!e"ile method are sa!ed in the bin directory of the 'indows pplication. Bou can !iew output of the abo!e said code in the image abo!e. La#e" /abels are those controls that are used to display text in other parts of the application. They are based on the 2ontrol class. Nota#"e %ro%ert' of the label control is the text property which is used to set the text for the label. La#e" Event The default e!ent of /abel is the 2lick e!ent which looks like this in code< 1ri!ate (ub /abel#Q2lick0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles /abel#.2lick End (ub Creating a La#e" in Co,e 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles -yBase./oad *im /abel# s New /abel03 /abel#.Text J 8/abel8 /abel#./ocation J New 1oint0#AF, Y%3

/abel#.(iEe J New (iEe0A%, A%3 -e.2ontrols. dd0/abel#3 End (ub

LinkLa#e" /ink/abel is similar to a /abel but they display a hyperlink. E!en multiple hyperlinks can be specified in the text of the control and each hyperlink can perform a different task within the application. They are based on the /abel class which is based on the 2ontrol class. Notable properties of the /ink/abel control are the cti!e/ink2olor, /ink2olor and /ink4isited which are used to set the link color. LinkLa#e" Event The default e!ent of /ink/abel is the /ink2licked e!ent which looks like this in code< 1ri!ate (ub /ink/abel#Q/ink2licked0By4al sender s (ystem.)bject, Q By4al e s (ystem.'indows."orms./ink/abel/ink2lickedE!ent rgs3Q +andles /ink/abel#./ink2licked End (ub Working with LinkLa#e" *rag a /ink/abel 0/ink/abel#3 onto the form. 'hen we click this /ink/abel it will take us to 8www.start!bdotnet.com8. The code for that looks like this<

1ri!ate (ub /ink/abel#Q/ink2licked0By4al sender s (ystem.)bject, By4alQ e s (ystem.'indows."orms./ink/abel/ink2lickedE!ent rgs3Q +andles /ink/abel#./ink2licked (ystem.*iagnostics.1rocess.(tart08www.start!bdotnet.com83 &using the start method of system.diagnostics.process class &process class gi!es access to local and remote processes End (ub Creating a LinkLa#e" in Co,e 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles -yBase./oad *im /ink/abel# s New /ink/abel03 /ink/abel#.Text J 8/abel8 /ink/abel#./ocation J New 1oint0#AF, Y%3 /ink/abel#.(iEe J New (iEe0A%, A%3 -e.2ontrols. dd0/ink/abel#3 End (ub Che&kBo0 2heckBoxes are those controls which gi!es us an option to select, say, Bes:No or True:"alse. checkbox is clicked to select and clicked again to deselect some option. 'hen a checkbox is selected a check 0a tick mark3 appears indicating a selection. The 2heckBox control is based on the TextBoxBase class which is based on the 2ontrol class. Below is the image of a 2heckbox.

Nota#"e +ro%erties Important properties of the 2heckBox in the window are< ppearance section of the properties

ppearance< *efault !alue is Normal. (et the !alue to Button if you want the 2heckBox to be displayed as a Button. BackgroundImage< >sed to set a background image for the checkbox. 2heck lign< >sed to set the alignment for the 2heckBox from a predefined list. 2hecked< *efault !alue is "alse, set it to True if you want the 2heckBox to be displayed as checked. 2heck(tate< *efault !alue is >nchecked. (et it to True if you want a check to appear. 'hen set to Indeterminate it displays a check in gray background. "lat(tyle< *efault !alue is (tandard. (elect the !alue from a predefined list to set the style of the checkbox. Important property in the Beha!ior section of the properties window is the Three(tate property which is set to "alse by default. (et it to True to specify if the 2heckbox can allow three check states than two. Che&kBo0 Event The default e!ent of the 2heckBox is the 2hecked2hange e!ent which looks like this in code<

1ri!ate (ub 2heckBox#Q2hecked2hanged0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles 2heckBox#.2hecked2hanged End (ub Working with Che&kBo0es /ets work with an example. *rag a 2heckBox 02heckBox#3, TextBox 0TextBox#3 and a Button 0Button#3 from the Toolbox. Co,e to ,is%"a' some te0t when the Che&k#o0 is &he&ke, 1ri!ate (ub 2heckBox#Q2hecked2hanged0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles 2heckBox#.2hecked2hanged TextBox#.Text J 82heckBox 2hecked8 End (ub Co,e to &he&k a Che&kBo0Gs state 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick If 2heckBox#.2hecked J True Then TextBox#.Text J 82hecked8 Else TextBox#.Text J 8>n2hecked8 End If End (ub Creating a Che&kBo0 in Co,e 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andlesQ -yBase./oad *im 2heckBox# s New 2heckBox03 2heckBox#.Text J 82heckbox#8 2heckBox#./ocation J New 1oint0#%%, F%3 2heckBox#.(iEe J New (iEe0$F, RF3 -e.2ontrols. dd02heckBox#3 End (ub

Ra,ioButton =adioButtons are similar to 2heckBoxes but =adioButtons are displayed as rounded instead of boxed as with a checkbox. /ike 2heckBoxes, =adioButtons are used to select and deselect options but they allow us to choose from mutually exclusi!e options. The =adioButton control is based on the ButtonBase class which is based on the 2ontrol class. major difference between 2heckBoxes and =adioButtons is, =adioButtons are mostly used together in a group. Below is the image of a =adioButton.

1m%ortant %ro%erties o! the Ra,ioButton in the .%%earan&e se&tion o! the %ro%erties win,ow are* ppearance< *efault !alue is Normal. (et the !alue to Button if you want the =adioButton to be displayed as a Button. BackgroundImage< >sed to set a background image for the =adioButton. 2heck lign< >sed to set the alignment for the =adioButton from a predefined list. 2hecked< *efault !alue is "alse, set it to True if you want the =adioButton to be displayed as checked. "lat(tyle< *efault !alue is (tandard. (elect the !alue from a predefined list to set the style of the =adioButton. Ra,ioButton Event The default e!ent of the =adioButton is the 2hecked2hange e!ent which looks like this in code< 1ri!ate (ub =adioButton#Q2hecked2hanged0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles =adioButton#.2hecked2hanged End (ub

Working with E0am%"es *rag a =adioButton 0=adioButton#3, TextBox 0TextBox#3 and a Button 0Button#3 from the Toolbox. Co,e to ,is%"a' some te0t when the Ra,ioButton is se"e&te, 1ri!ate (ub =adioButton#Q2hecked2hanged0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles =adioButton#.2hecked2hanged TextBox#.Text J 8=adioButton (elected8 End (ub Co,e to &he&k a Ra,ioButtonGs state 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick If =adioButton#.2hecked J True Then TextBox#.Text J 8(elected8 Else TextBox#.Text J 8Not (elected8 End If End (ub Creating a Ra,ioButton in Co,e 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andlesQ -yBase./oad *im =adioButton# s New =adioButton03 =adioButton#.Text J 8=adioButton#8 =adioButton#./ocation J New 1oint0#7%,?%3 =adioButton#.(iEe J New (iEe0#%%, F%3 -e.2ontrols. dd0=adioButton#3 End (ub ListBo0 The /istBox control displays a list of items from which we can make a selection. 'e can select one or more than one of the items from the list. The /istBox control is

based on the /ist2ontrol class which is based on the 2ontrol class. The image below displays a /istBox.

Nota#"e +ro%erties o! the ListBo0 1n the Behavior $e&tion +oriEontal(crollbar< *isplays a horiEontal scrollbar to the /istBox. 'orks when the /istBox has -ultiple2olumns. -ulti2olumn< The default !alue is set to "alse. (et it to True if you want the list box to display multiple columns. (croll lways4isible< *efault !alue is set to "alse. (etting it to True will display both 4ertical and +oriEontal scrollbar always. (election-ode< *efault !alue is set to one. (elect option None if you do not any item to be selected. (elect it to -ulti(imple if you want multiple items to be selected. (etting it to -ultiExtended allows you to select multiple items with the help of (hift, 2ontrol and arrow keys on the keyboard. (orted< *efault !alue is set to "alse. (et it to True if you want the items displayed in the /istBox to be sorted by alphabetical order. 1n the Data $e&tion Notable property in the *ata section of the 1roperties window is the Items property. The Items property allows us to add the items we want to be displayed in the

list box. *oing so is simple, click on the ellipses to open the (tring 2ollection Editor window and start entering what you want to be displayed in the /istBox. fter entering the items click )[ and doing that adds all the items to the /istBox. ListBo0 Event The default e!ent of /istBox is the (electedIndex2hanged which looks like this in code< 1ri!ate (ub /istBox#Q(electedIndex2hanged0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles /istBox#.(electedIndex2hanged End (ub Working with ListBo0es *rag a TextBox and a /istBox control to the form and add some items to the /istBox with it&s items property.

Re!erring to 1tems in the ListBo0 Items in a /istBox are referred by index. 'hen items are added to the /istBox they are assigned an index. The first item in the /istBox always has an index of % the next # and so on. Co,e to ,is%"a' the in,e0 o! an item 1ri!ate (ub /istBox#Q(electedIndex2hanged0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles /istBox#.(electedIndex2hanged TextBox#.Text J /istBox#.(electedIndex &using the selected index property of the list box to select the index End (ub 'hen you run the code and select an item from the /istBox, it&s index is displayed in the textbox.

Counting the num#er o! 1tems in a ListBo0 dd a Button to the form and place the following code in it&s click e!ent. 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e Q s (ystem.E!ent rgs3 +andles Button#.2lick TextBox#.Text J /istBox#.Items.2ount &counting the number of items in the /istBox with the Items.2ount End (ub 'hen you run the code and click the Button it will display the number of items a!ailable in the /istBox. Co,e to ,is%"a' the item se"e&te, !rom ListBo0 in a Te0tBo0 1ri!ate (ub /istBox#Q(electedIndex2hanged0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles /istBox#.(electedIndex2hanged TextBox#.Text J /istBox#.(electedItem &using the selected item property End (ub 'hen you run the code and click an item in the /istBox that item will be displayed in the TextBox. Co,e to Remove items !rom a ListBo0 Bou can remo!e all items or one particular item from the list box. Co,e to remove a %arti&u"ar item 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e Q s (ystem.E!ent rgs3 +andles Button#.2lick /istBox#.Items.=emo!e t0R3 &remo!ing an item by specifying it&s index End (ub Co,e to Remove a"" items 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, Q By4al e s (ystem.E!ent rgs3 +andles Button#.2lick

/istBox#.Items.2lear03 &using the clear method to clear the list box End (ub Com#oBo0 2omboBox is a combination of a TextBox and a /istBox. The 2omboBox displays an editing field 0TextBox3 combined with a /istBox allowing us to select from the list or to enter new text. 2omboBox displays data in a drop9down style format. The 2omboBox class is deri!ed from the /istBox class. Below is the Image of a 2omboBox.

Nota#"e %ro%erties o! the Com#oBo0 The *rop*own(tyle property in the ppearance section of the properties window allows us to set the look of the 2omboBox. The default !alue is set to *rop*own which means that the 2omboBox displays the Text set by it&s Text property in the Textbox and displays it&s items in the *rop*own/istBox below. (etting it to simple makes the 2omboBox to be displayed with a TextBox and the list box which doesn&t drop down. (etting it to *rop*own/ist makes the 2omboBox to make selection only from the drop down list and restricts you from entering any text in the textbox. 'e can sort the 2omboBox with it&s (orted property which is set to "alse by *efault. 'e can add items to the 2omboBox with it&s Items property. Com#oBo0 Event

The default e!ent of 2omboBox is (electedIndex2hanged which looks like this in code< 1ri!ate (ub 2omboBox#Q(electedIndex2hanged0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles 2omboBox#.(electedIndex2hanged End (ub Working with Com#oBo0es *rag a 2omboBox and a TextBox control onto the form. To display the selection made in the 2omboBox in the Textbox the code looks like this< 1ri!ate (ub 2omboBox#Q(electedIndex2hanged0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles 2omboBox#.(electedIndex2hanged TextBox#.Text J 2omboBox#.(electedItem &selecting the item from the 2omboBox with selected item property End (ub

Removing items !rom a Com#oBo0 Bou can remo!e all items or one particular item from the list box part of the 2omboxBox. 2ode to remo!e a particular item by it&s Index number looks like this< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick 2omboBox#.Items.=emo!e t0R3 &remo!ing an item by specifying it&s index End (ub Co,e to remove a"" items !rom the Com#oBo0

1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick 2omboBox#.Items.2lear03 &using the clear method to clear the list box End (ub TreeView The tree !iew control is used to display a hierarchy of nodes 0both parent, child3. Bou can expand and collpase these nodes by clicking them. This control is similar to 'indows Explorer which displays a tree !iew in it&s left pane to list all the folders on the hard disk. Below is the image of a Tree 4iew control.

Nota#"e +ro%erties o! TreeView Bounds< @ets the actual bound of the tree node 2hecked< @ets:(ets whether the tree node is checked "irstNode< @ets the first child tree node "ull1ath< @ets the path from the root node to the current node ImageIndex< @ets:(ets the image list index of the image displayed for a node Index< @ets the location of the node in the node collection IsEditing< @ets whether the node can be edited IsExpaned< @ets whether the node is expaned Is(elected< @ets whether the node is selected /astNode< @ets the last child node NextNode< @ets the next sibling node

Next4isibleNode< @ets the next !isible node Node"ont< @ets:(ets the font for nodes Nodes< @ets the collection of nodes in the current node 1arent< @ets the parent node of the current node 1re!Node< @ets the pre!ious sibling node 1re!4isibleNode< @ets the pre!ious !isible node Tree4iew< @ets the node&s parent tree !iew TreeView Event *efault e!ent of the Tree 4iew control is the fter(elect e!ent which looks like this in code< 1ri!ate (ub Tree4iew#Q fter(elect0By4al sender s (ystem.)bject, By4al e sQ (ystem.'indows."orms.Tree4iewE!ent rgs3 +andles Tree4iew#. fter(elect End (ub Working with Tree Views *rag a Tree 4iew control on to a form and to add nodes to it select the nodes property in the properties window, which displays the TreeNode editor as shown below.

To start adding nodes, you should click the dd =oot button, which adds a top9 le!el node. To add child nodes to that node, you should select that node and use the dd 2hild button. To set text for a node, select the node and set it&s text in the textbox as shown in the image abo!e. ssuming you added some nodes to the tree !iew, drag two /abels 0/abel#, /abel73 from the toolbox on to the form. The following code displays the node you select on /abel7 and the path to that node on /abel#. The code looks like this< 1ublic 2lass "orm#7 Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 ;End =egion 1ri!ate (ub Tree4iew#Q fter(elect0By4al sender s (ystem.)bject, By4al e sQ (ystem.'indows."orms.Tree4iewE!ent rgs3 +andles Tree4iew#. fter(elect /abel#.Text J 8Bou are here9I8 L 8 8 L e.Node."ull1ath &displaying the path of the selected node /abel7.Text J 82urrent node selected<8 L 8 8 L e.Node.Text &displaying the selected node End (ub End 2lass The image below displays sample output from abo!e code.

Che&ke,ListBo0 s the name says, 2hecked/istBox is a combination of a /istBox and a 2heckBox. It displays a /istBox with a 2heckBox towards it&s left. The 2hecked/istBox class is deri!ed from the /istBox class and is based on that class. (ince the 2hecked/istBox is deri!ed from the /istBox it shares all the members of /istBox. Below is the Image of a 2hecked/istBox.

Nota#"e +ro%erties o! Che&ke,ListBo0 The notable property in the appearance section of the properties window is the Three*2heckBoxes property which is set to "alse by default. (etting it to True makes the 2hecked/istBox to be displayed in "lat or Normal style. Notable property in the beha!ior section is the 2heck)n2lick property which is set to "alse by default. 'hen set to "alse it means that to check or uncheck an item in the 2hecked/istBox we need to double9click the item. (etting it to True makes an item in the 2hecked/istBox to be checked or unchecked with a single click. Notable property in the *ata section is the Items property with which we add items to the 2hecked/istBox. 1ri!ate (ub 2hecked/istBox#Q(electedIndex2hanged0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles 2hecked/istBox#.(electedIndex2hanged End (ub

'orking with 2hecked/istBoxes is similar to working with /istBoxes. 1lease refer to examples in that section her +ane" 1anels are those controls which contain other controls, for example, a set of radio buttons, checkboxes, etc. 1anels are similar to @roupboxes but the difference, 1anels cannot display captions where as @roupBoxes can and 1anels can ha!e scrollbars where as @roupBoxes can&t. If the 1anel&s Enabled property is set to "alse then the controls which the 1anel contains are also disabled. 1anels are based on the (crollable2ontrol class. Nota#"e %ro%ert' of the 1anel control in the appearance section is the Border(tyle property. The default !alue of the Border(tyle property is set to None. Bou can select from the predefined list to change a 1anels Border(tyle. Notable property in the layout section is the uto(croll property. *efault !alue is set to "alse. (et it to True if you want a scrollbar with the 1anel. .,,ing Contro"s to a +ane" )n a from drag a 1anel 01anel#3 from the toolbox. 'e want to place some controls, say, checkboxes on this 1anel. *rag three checkboxes from the toolbox and place them on the 1anel. 'hen that is done all the checkboxes in the 1anel are together as in a group but they can function independently. Creating a +ane" an, a,,ing a La#e" an, a Che&kBo0 to it in Co,e 1ri!ate (ub "ormAQ/oad0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -yBase./oad *im 1anel# s New 1anel03 *im 2heckBox# s New 2heckBox03 *im /abel# s New /abel03 1anel#./ocation J New 1oint0A%, ?%3 1anel#.(iEe J New (iEe07%%, 7?R3 1anel#.Border(tyle J Border(tyle."ixedA* &setting the borderstyle of the panel -e.2ontrols. dd01anel#3 2heckBox#.(iEe J New (iEe0$F, RF3 2heckBox#./ocation J New 1oint07%, A%3 2heckBox#.Text J 82heckbox#8 /abel#.(iEe J New (iEe0#%%, F%3 /abel#./ocation J New 1oint07%, R%3 /abel#.Text J 82heck-e8 1anel#.2ontrols. dd02heckBox#3 1anel#.2ontrols. dd0/abel#3

&adding the label and checkbox to the panel End (ub The image #e"ow ,is%"a's a %ane".

Arou%Bo0 Contro" s said abo!e, @roupboxes are used to @roup controls. @roupBoxes display a frame around them and also allows to display captions to them which is not possible with the 1anel control. The @roupBox class is based on the 2ontrol class. Creating a Arou%Bo0 an, a,,ing a La#e" an, a Che&kBo0 to it in Co,e 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -yBase./oad *im @roupBox# s New @roupBox03 *im 2heckBox# s New 2heckBox03 *im /abel# s New /abel03 @roupBox#./ocation J New 1oint0A%, ?%3 @roupBox#.(iEe J New (iEe07%%, 7?R3 @roupBox#.Text J 8In@roupBox8

&setting the caption to the groupbox -e.2ontrols. dd0@roupBox#3 2heckBox#.(iEe J New (iEe0$F, RF3 2heckBox#./ocation J New 1oint07%, A%3 2heckBox#.Text J 82heckbox#8 label#.(iEe J New (iEe0#%%, F%3 /abel#./ocation J New 1oint07%, R%3 /abel#.Text J 82heck-e8 @roupBox#.2ontrols. dd02heckBox#3 @roupBox#.2ontrols. dd0/abel#3 &adding the label and checkbox to the groupbox End (ub +i&tureBo0 Contro" 1ictureBoxes are used to display images on them. The images displayed can be anything !arying from Bitmap, 51E@, @I", 1N@ or any other image format files. The 1ictureBox control is based on the 2ontrol class. Notable property of the 1ictureBox 2ontrol in the ppearance section of the properties window is the Image property which allows to add the image to be displayed on the 1ictureBox. .,,ing 1mages to +i&tureBo0 Images can be added to the 1ictureBox with the Image property from the 1roperties window or by following lines of code. 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject,Q By4al e s (ystem.E!ent rgs3 +andles Button#.2lick 1ictureBox#.Image J Image."rom"ile082<Hsample.gif83 &loading the image into the picturebox using the "rom"ile method of the image class &assuming a @I" image named sample in 2< dri!e End (ub Too"Ti% ToolTips are those small windows which display some text when the mouse is o!er a control gi!ing a hint about what should be done with that control. ToolTip is not a control but a component which means that when we drag a ToolTip from the toolbox onto a form it will be displayed on the component tray. To assign ToolTip&s with controls we use it&s (etToolTip method.

Nota#"e %ro%ert' of the ToolTip is the cti!e property which is set to True by default and which allows the tool tip to be displayed. $etting a Too"Ti% ssume that we ha!e a TextBox on the form and we want to display some text when your mouse is o!er the TextBox. (ay the text that should appear is 8*o not lea!e this blank8. The code for that looks like this< 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -yBase./oad ToolTip#.(etToolTip0TextBox#, 8*o not lea!e this blank83 End (ub The image below displays output from abo!e code.

Error+rovi,er Com%onent The Error1ro!ider component pro!ides an easy way to set !alidation errors. It allows us to set an error message for any control on the form when the input is not !alid. 'hen an error message is set, an icon indicating the error will appear next to the control and the error message is displayed as Tool Tip when the mouse is o!er the control. Nota#"e %ro%ert' of Error1ro!ider in the ppearance section is the Icon property which allows us to set an icon that should be displayed. Notable property in Beha!ior section is the Blink=ate property which allows to set the rate in milliseconds at which the icon blinks. Dis%"a'ing an Error

/et&s work with an example. ssume we ha!e a TextBox and a Button on a form. If the TextBox on the form is left blank and if the Button is clicked, an icon will be displayed next to the TextBox and the specified text will appear in the Tool Tip box when the mouse is o!er the control. The code for that looks like this< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick If TextBox#.Text J 88 Then Error1ro!ider#.(etError0TextBox#, 82annot lea!e textbox blank83 Else Error1ro!ider#.(etError0TextBox#, 883 End If End (ub The image below displays output from abo!e code.

5enus E!eryone should be familiar with -enus. -enus 0"ile, Edit, "ormat etc in all windows applications3 are those that allow us to make a selection when we want to perform some action with the application, for example, to format the text, open a new file, print and so on. In 4B .NET -ain-enu is the container for the -enu structure of the form. -enus are made of -enuItem objects that represent indi!idual parts of a menu 0like "ile9INew, )pen, (a!e, (a!e s etc3. The two main classes in!ol!ed in menu handling are, -ain-enu and -enuItem. The -ain-enu class let&s us assign objects to a form&s menu class and -enuItem is the class which supports the items in a menu system. -enus like "ile, Edit, "ormat etc and the items in those -enus are supported by this -enuItem class. It&s this -enuItem&s click e!ent that makes these -enus work. "or a -enuItem to be displayed, we need to add it to a -ain-enu object.

Event o! the 5enu1tem The default e!ent of the -enuItem is the 2lick e!ent which looks like this in code< 1ri!ate (ub -enuItem#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItem#.2lick End (ub Nota#"e %ro%erties of the -enuItem class are summariEed below. 6n,er the 5is&e""aneous $e&tion o! the %ro%erties win,ow* 2hecked< *efault !alue is set to "alse. 2hanging it to True makes a checkmark appear towards the left of the -enu. *efaultItem< *efault !alue is set to "alse. 2hanging it to True makes this menu item default menu item. =adio2heck< 2hanging it to True makes a menu item display a radio button instead of a checkmark. (hortcut< Enables to set a short cut key from a list of a!ailable shortcuts for the menu item. Working with 5enus 2reating -enus is simple. *rag a -ain-enu component from the toolbar onto the form. 'hen you add a -aiu-enu component to the form it appears in the component tray below the form. 'indows form designer will add the -enuItem&s for this by default, you need not add this. )nce when you finish adding a -ain-enu component to the form you will notice a 8Type+ere8 box towards the top9left corner of the form. To create a menu all you ha!e to do is click on the 8Type+ere8 text which opens up a small textbox allowing you to enter text for the menu. Bou can !iew that in the image below. Bou can use the arrow keys on the keyboard to create a submenu or add other items to that menu or click on the first menu item and use the left:right arrow keys on the keyboard to create a new menu item. That&s all it takes to add a menu to the form.

Working with an e0am%"e /et&s work with an example to understand -enus. *rag a -ain-enu and a TextBox onto the form. In the 8Type +ere8 part, type "ile and under file type 8New8 and 8Exit8. )ur intention here is to display 8'elcome to -enus8 in the TextBox when 8New8 is clicked and close the form when 8Exit8 is clicked. The -enu which we will create should look like this "ile9INew, Exit 0New and Exit below "ile3. The code for that looks like this< 1ublic 2lass "ormA Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 1ri!ate (ub -enuItem7Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3Q +andles -enuItem7.2lick TextBox#.Text J 8'elcome to -enus8 End (ub 1ri!ate (ub -enuItemAQ2lick0By4al sender s (ystem.)bject, By4al e s (ystem.E!ent rgs3Q +andles -enuItemA.2lick -e.2lose03 &-e refers to the current object 0form3 End (ub

End 2lass

$e%erating 5enu 1tems 'e can separate menu items with a seperator. separator is a horiEontal line between items on a menu. 'e can use separator bars to di!ide menu items into groups on menus that contain multiple items. Bou add a separator to menus by entering a hypen 093 as the text of a menu item. It will be displayed as a separator. The image below displays a separator bewteen the 2lose and Exit menu items.

C"oning 5enus 2loning menus is making a copy of existing menu items. "or example, we can clone the "ile menu item displayed in the image below to ser!e as a context menu for a control. To clone a menu we should use the 2lone-enu method. The 2lone-enu method creates a copy of the specified menu and all of it&s members. This includes their properties and e!ent handlers. Thus, all the e!ents that are handled by the menu item will be handled by the cloned menu. The cloned menu can then be assigned to a control. E0am%"e )n a new form drag a -ain-enu component, 2ontext-enu component and a Button. 2lick on the -ain-enu component and under the 8type here8 boxes enter the menu items as shown in the image below. The menu items you entered for -ain-enu will appear as a context menu 0right9click3 for the button control. "or the purpose of

explanation minimum functionality is added to the menu items. The image below displays the form in design !iew.

Co,e to &"one the 5ain5enu &om%onent 1ublic 2lass "ormR Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 ;End =egion 1ri!ate (ub "ormRQ/oad0By4al sender s (ystem.)bject, By4al e s Q (ystem.E!ent rgs3 +andles -yBase./oad 2ontextmenu#.-enuItems. dd0-enuItem#.2lone-enu3 &cloning the filemenuitem and filling contextmenu# with the cloned item Button#.2ontext-enu J 2ontextmenu# &assigning the new contextmenu to button# End (ub 1ri!ate (ub -enuItem7Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItem7.2lick -essageBox.(how08Bou clicked New83 End (ub

1ri!ate (ub -enuItemAQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemA.2lick -essageBox.(how08Bou clicked )pen83 End (ub 1ri!ate (ub -enuItemRQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemR.2lick -essageBox.(how08Bou clicked 2lose83 End (ub 1ri!ate (ub -enuItem?Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItem?.2lick -e.2lose03 End (ub End 2lass The image below displays output from the code abo!e. 'hen you right9click the button and click on any menu item, it performs the same functionality as it would for the "ile menu item.

$hort&ut He's Bou can assign shortcut keys to enable instant access to menu commands. To assign a shortcut to the menu item, in the properties window select the shortcut property and choose the appropriate shortcut key combination from the drop9down menu. Conte0t 5enus 2ontext menus are menus that appear when an item is right9clicked. In any windows application when you right9click your mouse you get a menu which might display some shortcuts from the Edit -enu, for example, cut, copy, paste, paste special and so on. ll these menu items which are a!ailable when you right9click are called 2ontext -enus. In 4isual Basic we create context menus with the 2ontext-enu component. The 2ontext-enu component is edited exactly the same way the -ain-enu component is edited. The 2ontext-enu appears at the top of the form and you can add menu items by typing them. To associate a 2ontext-enu with a particular form or control we need to set the 2ontext-enu property of that form or control to the appropriate menu. Working With E0am%"e /et&s understand 2ontext-enus with an example. )n a new "orm drag a 2ontext-enu component from the toolbox. 2lick on the 2ontext-enu component to open the editor at the top of the form. In the type here box, enter cut, copy, paste. 2ut is assigned -enuItem#, 2opy with -enuItem7 and 1aste with -enuItemA. *arg two =ichTextBoxes onto the form. In the properties window for the form and the richtextboxes, select the 2ontext-enu property and set it to 2ontext-enu#. -ake sure you set the 2ontext-enu property for both the richtextboxes. This sample application allows you to enter some text in =ichTextBox#, select some text, cut:copy the slected text and paste it in =ichTextBox7. It is similar to the right9click menu with which you work in other windows applications. The whole design should look like the image below.

Co,e to get the ,esire, resu"t "ooks "ike this* 1ublic 2lass "ormA Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 ;End =egion 1ri!ate (ub -enuItem#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -enuItem#.2lick =ichTextBox#.2ut03 End (ub 1ri!ate (ub -enuItem7Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -enuItem7.2lick =ichTextBox#.2opy03 End (ub 1ri!ate (ub -enuItemAQ2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -enuItemA.2lick =ichTextBox7.1aste03 End (ub End 2lass Bou can run the application, enter some text in richtextbox#, cut:copy it and paste it in richtextbox7. The images below display sample output from the abo!e said code.

Common Dia"ogs 4isual Basic .NET comes with built9in dialog boxes which allow us to create our own "ile )pen, "ile (a!e, "ont, 2olor dialogs much like what we see in all other windows applications. To make a dialog box !isible at run time we use the dialog box&s (how*ialog method. The *ialog Boxes which come with 4isual Basic .NET are< )pen"ile*ialog, (a!e"ile*ialog, "ont*ialog, 2olor*ialog, 1rint*ialog, 1rint1re!iew*ialog and 1age(etup*ialog. 'e will be working with )pen"ile, (a!e"ile, "ont and 2olor *ialog&s in this section. The return !alues of all the abo!e said dialog boxes which will determine which selection a user makes are< bort, 2ancel, Ignore, No, None, )[, =eturn, =etry and Bes. 2%enFi"eDia"og )pen "ile *ialog&s are supported by the )pen"ile*ialog class and they allow us to select a file to be opened. Below is the image of an )pen"ile*ialog.

+ro%erties o! the 2%enFi"eDia"og are as !o""ows* ddExtension< @ets:(ets if the dialog box adds extension to file names if the user doesn&t supply the extension. 2heck"ileEixsts< 2hecks whether the specified file exists before returning from the dialog. 2heck1athExists< 2hecks whether the specified path exists before returning from the dialog. *efaultExt< llows you to set the default file extension. "ileName< @ets:(ets file name selected in the file dialog box. "ileNames< @ets the file names of all selected files.

"ilter< @ets:(ets the current file name filter string, which sets the choices that appear in the 8"iles of Type8 box. "ilterIndex< @ets:(ets the index of the filter selected in the file dialog box. Initial*irectory< This property allows to set the initial directory which should open when you use the )pen"ile*ialog. -ulti(elect< This property when set to True allows to select multiple file extensions. =ead)nly2hecked< @ets:(ets whether the read9only checkbox is checked. =estore*irectory< If True, this property restores the original directory before closing. (how+elp< @ets:(ets whether the help button should be displayed. (how=ead)nly< @ets:(ets whether the dialog displays a read9only check box. Title< This property allows to set a title for the file dialog box. 4alidateNames< This property is used to specify whether the dialog box accepts only !alid file names. $aveFi"eDia"og (a!e "ile *ialog&s are supported by the (a!e"ile*ialog class and they allow us to sa!e the file in a specified location. Below is the image of a (a!e"ile*ialog.

1roperties of the (a!e "ile *ialog are the same as that of the )pen "ile *ialog. 1lease refer abo!e. Notable property of (a!e "ile dialog is the )!erwrite1romopt property which displays a warning if we choose to sa!e to a name that already exists. FontDia"og "ont *ialog&s are supported by the "ont*ialog 2lass and they allow us to select a font siEe, face, style, etc. Below is the image of a "ont*ialog.

+ro%erties o! the FontDia"og are as !o""ows* llow(imulations< @ets:(ets whether the dialog box allows graphics de!ice interface font simulations. llow4ector"onts< @ets:(ets whether the dialog box allows !ector fonts. llow4ertical"onts< @ets:(ets whether the dialog box displays both !ertical and horiEontal fonts or only horiEontal fonts. 2olor< @ets:(ets selected font color. "ixed1itch)nly< @ets:(ets whether the dialog box allows only the selection of fixed9pitch fonts. "ont< @ets:(ets the selected font. "ont-ustExist< @ets:(ets whether the dialog box specifies an error condition if the user attempts to select a font or siEe that doesn&t exist. -ax(iEe< @ets:(ets the maximum point siEe the user can select. -in(iEe< @ets:(ets the mainimum point siEe the user can select. (how pply< @ets:(ets whether the dialog box contains an apply button. (how2olors< @ets:(ets whether the dialog box displays the color choice. (howEffects< @ets:(ets whether the dialog box contains controls that allow the user to specify to specify strikethrough, underline and text color options. (how+elp< @ets:(ets whether the dialog box displays a help button.

Co"orDia"ogs 2olor *ialog&s are supported by the 2olor*ialog 2lass and they allow us to select a color. The image below displays a color dialog.

+ro%erties o! Co"orDia"og are as !o""ows* llow"ull)pen< @ets:(ets whether the user can use the dialog box to define custom colors. ny2olor< @ets:(ets whether thedialog box displays all the a!ailable colors in the set of basic colons. 2olor< @ets:(ets the color selected by the user. 2ustom2olors< @ets:(ets the set of custom colors shown in the dialog box. "ull)pen< @ets:(ets whether the controls used to create custom colors are !isible when the dialog box is opened. (how+elp< @ets:(ets whether the dialog box displays a help button. (olid2olor)nly< @ets:(ets whether the dialog box will restrict users to selecting solid colors only. Dia"og Bo0es +utting Dia"og Bo0es to Work 'e will work with )pen"ile, (a!e"ile, "ont and 2olor *ialog&s in this section. "rom the toolbox drag a -ain-enu component, =ichTextBox control, Button 2ontrol, )pen"ile*ialog, (a!e"ile*ialog, "ont*ialog and 2olor*ialog onto the form. The sample code demonstrated below allows you to select a file to be opened and displays it in the =ichTextBox with )pen"ile*ialog, allows you to sa!e the text you enter in the =ichTextBox to a location using the (a!e"ile*ialog, allows you to select a font and applies the selected font to text in the =TB using "ont*ialog and allows you to select a color and applies the color to text in the =TB using the 2olor*ialog. (elect the -ain-enu component and in the 8Type +ere8 part of the -ain-enu type "ile and using the down arrow keys on the keyboard start typing )pen, (a!e, (elect"ont and (elect2olor under the "ile menu. It should look like this< "ile9I )pen, (a!e, (elect"ont, (elect2olor. 'e will assign )pen"ile*ialog to )pen, (a!e"ile*ialog to (a!e, "ont*ialog to (elect"ont and 2olor*ialog to (elect2olor under "ile -enu. The form in design !iew should look similar to the image below.

Before proceeding further you need to set properties for these dialogs in their properties window. They are listed below. "or )pen"ile*ialog#, set the *efaultExt property to txt so that it opens text files, Initial*irectory property to 2<, =estore*irectory propery to True and the Text property to )pen "ile "rom. "or (a!e"ile*ialog#, set the *efaultExt property to txt so that it sa!es files in text format, Initial*irectory property to 2< so that when you sa!e a file, it first pro!ides 2< dri!e as the choice of location, )!erwrite1rompt property to "alse, =estore*irectory propery to True and the Text property to (a!e "ile In. "or "ont*ialog#, set the llow(imulations, llow4ector"onts, llow!ertical"onts properties to false, -ax(iEe to F%, -in(iEe to F and (how pply and (how2olor properties to True. "or 2olor*ialog#, set ny2olor and (olid2olor)nly properties to True. Co,e Imports (ystem.I)

1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 ;End =egion 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick =ichTextBox#.Text J 8 8 &clears the text in richtextbox End (ub 1ri!ate "ileName s (tring &declaring filename that will be selected *im sr s (tream=eader &streamreader is used to read text 1ri!ate (ub -enuItem7Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItem7.2lick Try 'ith )pen"ile*ialog# &'ith statement is used to execute statements using a particular object, here,Q &)pen"ile*ialog# ."ilter J 8Text files 0V.txt3TV.txtT8 L 8 ll filesTV.V8 &setting filters so that Text files and ll "iles choice appears in the "iles of Type box &in the dialog If .(how*ialog03 J *ialog=esult.)[ Then &show*ialog method makes the dialog box !isible at run time "ileName J ."ileName sr J New (tream=eader0.)pen"ile3 &using streamreader to read the opened text file =ichTextBox#.Text J sr.=eadToEnd03 &displaying text from streamreader in richtextbox End If End 'ith 2atch es s Exception -essageBox.(how0es.-essage3 "inally If Not 0sr Is Nothing3 Then sr.2lose03 End If

End Try End (ub 1ri!ate (ub -enuItemAQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemA.2lick *im sw s (tream'riter &streamwriter is used to write text Try 'ith (a!e"ile*ialog# ."ileName J "ileName ."ilter J 8Text files 0V.txt3TV.txtT8 L 8 ll filesTV.V8 If .(how*ialog03 J *ialog=esult.)[ Then "ileName J ."ileName sw J New (tream'riter0"ileName3 &using streamwriter to write text from richtextbox and sa!ing it sw.'rite0=ichTextBox#.Text3 End If End 'ith 2atch es s Exception -essageBox.(how0es.-essage3 "inally If Not 0sw Is Nothing3 Then sw.2lose03 End If End Try End (ub 1ri!ate (ub -enuItemRQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemR.2lick Try 'ith "ont*ialog# ."ont J =ichTextBox#."ont &initialiEing the dialog box to match the font used in the richtextbox .2olor J =ichTextBox#."ore2olor &default color is Black If .(how*ialog J *ialog=esult.)[ Then set"ont03 &calling a method set"ont03 to set the selected font and color End If End 'ith 2atch es s Exception -essageBox.(how0es.-essage3 End Try

End (ub 1ri!ate (ub set"ont03 Try 'ith "ont*ialog# =ichTextBox#."ont J ."ont If .(how2olor Then =ichTextBox#."ore2olor J .2olor &setting the color End If End 'ith 2atch ex s Exception -essageBox.(how0ex.-essage3 End Try End (ub 1ri!ate (ub -enuItemFQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemF.2lick (tatic 2ustom2olors03 s Integer J S=@B07FF, %, %3, =@B0%, 7FF, %3, =@B0%, %, 7FF3U &initialiEing 2ustom2olors with an array of integers and putting =ed, @reen, &and Blue in the custom colors section Try 'ith 2olor*ialog# .2olor J =ichTextBox#."ore2olor &initialiEing the selected color to match the color currently used &by the richtextbox&s foreground color .2ustom2olors J 2ustom2olors &filling custom colors on the dialog box with the array declared abo!e If .(how*ialog03 J *ialog=esult.)[ Then =ichTextBox#."ore2olor J .2olor 2ustom2olors J .2ustom2olors &(toring the custom colors to use again End If 2olor*ialog#.=eset03 &resetting all colors in the dialog box End 'ith 2atch es s Exception -essageBox.(how0es.-essage3 End Try End (ub End 2lass

Date Time+i&ker *ate Time1icker allows us to select date and time. *ate Time1icker is based on the control class. 'hen we click on the drop9down arrow on this control it displays a month calendar from which we can make selections. 'hen we make a selection that selection appears in the textbox part of the *ate Time1icker. The image below displays the *ate Time1icker. Nota#"e +ro%erties of *ate Time1icker The "ormat property in the ppearance section is used to select the format of the date and time selected. *efault !alue is long which displays the date in long format. )ther !alues include short, time and custom Behavior $e&tion The 2ustom"ormat property allows us to set the format for date and time depending on what we like. To use the 2ustom"ormat property we need to set the "ormat property to 2ustom. The -ax*ate 1roperty allows us to set the maximum date we want the *ate Time1icker to hold. *efault -ax*ate !alue set by the software is #7:A#:$$$X . The -in*ate 1roperty allows us to set the minimum date we want the *ate Time1icker to hold. *efault -in*ate !alue set by the software is #:#:#YFA . 5onthCa"en,ar The -onth2alendar control allows us to select date. The difference between a *ate Time1icker and -onth2alendar is, in -onth2alendar we select the date !isually and in *ate Time1icker when we want to make a selection we click on the drop9down arrow and select the date from the -onth2alendar which is displayed. The image below displays a -onth2alendar control.

Nota#"e Behavior properties of -onth2alendar "irst*ay)f'eek< *efault !alue is *efault which means that the week starts with (unday as the first day and (aturday as last. Bou can set the first day of the week depending upon your choice by selecting from the predefined list with this property. (howToday< *efault !alue is set to True which displays the current date at the bottom of the 2alendar. (etting it to "alse will hide it. (howToday2ircle< *efault !alue is set to True which displays a red circle on the current

date. (etting it to "alse will make the circle disappear. (how'eekNumber< *efault is "alse. (etting it to True will display the week number of the current week in the F7 week year. That will be displayed towards the left side of the control.

$%"itter The (plitter control is used to resiEe other controls. The main purpose of (plitter control is to sa!e space on the form. )nce when we finish working with a particular control we can mo!e it away from it&s position or resiEe them with (plitter control. The (plitter control is in!isible when we run the application but when the mouse is o!er it, the mouse cursor changes indicating that it&s a (plitter control and it can be resiEed. This control can be !ery useful when we are working with controls both at design time and run time 0which are not !isible at design time3. The (plitter control is based on the 2ontrol class. Working with $%"itter Contro" To work with a (plitter 2ontrol we need to make sure that the other control with which this control works is docked towards the same side of the container. /et&s do that with an example. ssume that we ha!e a TextBox on the form. *rag a (plitter control onto the form. (et the TextBox&s dock property to left. If we want to resiEe the TextBox once we finish using it set the (plitter&s dock property to left 0both the controls should be

docked towards the same end3. 'hen the program is executed and when you pass the mouse o!er the (plitter control it allows us to resiEe the TextBox allowing us to mo!e it away from it&s current position. @e"%+rovi,er 1ro!iding help with your application is !ery useful as it allows your users to understand it more easily, thereby increasing producti!ity and sa!ing some money. (upport for help in 4isual Basic exists and you can display +T-/ files that can contain a set of linked topics. @e"% C"ass The +elp class allows us to display +T-/ help to users. The +elp class pro!ides two methods< (how+elp and (how+elpIndex. (how+elp is used to display a help file for a particular control and re6uires that control to be displayed along with the help file. The >=/ you specify for the help file can be in the form of 2<Hmy+elp 0local machine3 or http<HHwww.start!bdotnet.comHhelp.htm 0'eb3. @enerally, the +elp class is used in conjunction with -enus, 2ontext -enus. E0am%"e The following code displays a help file. This code assumes that you ha!e a Button, Button#, /abel, /abel# on the form and a help file named pphelp.htm in the 2< dri!e of your machine. 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles Button#.2lick +elp.(how+elp0/abel#, 82<H pphelp.htm83 &using the +elp class with label control End (ub The (how+elpIndex method is used to display the index of a specified help file. Bou call the (how+elpIndex method just like you call the (how+elp method. @e"%+rovi,er Com%onent +elp1ro!ider2omponent allows us to pro!ide help for controls on the form when "# key is pressed. The +elp1ro!ider2omponent is an extender pro!ider which means that it coordinates and maintains properties for each control on the form. Notable 1roperty of +elp1ro!ider component is the +elpName(pace property which specifies the >=/ for the help file associated with it. The +elp1ro!ider component pro!ides three additional properties to each control on the form. These properties are<

+elp(tring< *etermines the help string associated with a control. +elp[ey'ord< *etermines the help keyword associated with a control. +elpNa!igator< *etermines the kind of help associated with a control. 1ro!ides six !alues< Table)f2ontents, "ind, Index, Topic, ssociatedIndex and [eywordIndex. The abo!e said three properties are !isible in the properties window for each control once the +elp1ro!ider component is added to the form. If the +elpName(pace property is not set, the +elp(tring is automatically displayed, and other two properties are ignored. E0am%"e *rag two Buttons and the +elp1ro!ider component onto the form. The following code displays a help string when Button7 has the focus and "# key is pressed. 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s Q (ystem.E!ent rgs3 +andles -yBase./oad +elp1ro!ider#.(et+elp(tring0Button7, 8I am supported by +elp1ro!ider#83 &button7 needs to ha!e focus to display this string when "# is pressed End (ub The image below displays output from code abo!e.

$tatusBar (tatus Bars are used to display status messages at the bottom of the form. They are generally used to pro!ide additional information, such as page numbers, display a

message, etc. There are two kinds of status bars< simple status bars and status bars that display a panel. (imple status bars display a single message on the status bar and a status bar with panels can display multiple messages. Below is the image of a (tatusBar control.

Nota#"e %ro%erties of the (tatus bar< 1anels< @ets the collection of status bar panels in a status bar. (how1anels< *efault is True. Bou can set it to "alse if you don&t want to show panels. Text< @ets:(ets the text to be displayed. $tatusBar Event *efalut e!ent of the (tatusBar control is the 1anel2lick e!ent which looks like this in 2ode< 1ri!ate (ub (tatusBar#Q1anel2lick0By4al sender s (ystem.)bject, By4al e Q s (ystem.'indows."orms.(tatusBar1anel2lickE!ent rgs3 +andles (tatusBar#.1anel2lick End (ub $am%"e &o,e !or a $im%"e $tatus Bar "rom the toolbox add a status bar control to the form. The following code will display the message 8+ello8 on the (tatusBar when the form loads. 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s

Q (ystem.E!ent rgs3 +andles -yBase./oad (tatusBar#.Text J 8+ello8 End (ub $tatus Bars with +ane"s Bou can add panels to a status bar by opening it&s properties window and clicking the 1anels property. 'hen you click the 1anels property it opens the (tatusBar1anel 2ollection Editor which looks like the image below.

Bou add panels by clicking the dd button found in the editor. 'hile adding panels you can set the Text to be displayed for each panel, an icon, tooltip, width for each panel you add. To add panels to status bar in code we use the (tatusBar.1anel. dd method and (tatusBar.1anels.=emo!e, (tatusBar.1anels.=emo!e t to remo!e the panels. To access text in each panel you use the text property of (tatusbar1anel as< (tatusBar1anels0%3.TextJ8I am panel one8.

To handle status bar panel clicks you use the 1anel2lick e!ent as shown in the code below. To work with this code, add a status bar control to the form, open it&s properties window, select the 1anels property and add three status bar panels. "or (tatusBar1anel# set the text 8-ore 4B .NET, 1lease 4isit 9I8, for (tatusBar1anel7 set the text 8-(*N8 and for (tatusBar1anelA 8(tart!bdotnet.com8. The form in design !iew should look like the image below.

(witch to code !iew and paste the following code< 1ri!ate (ub (tatusBar#Q1anel2lick0By4al sender s (ystem.)bject, By4al e s Q (ystem.'indows."orms.(tatusBar1anel2lickE!ent rgs3 +andles (tatusBar#.1anel2lick If e.(tatusBar1anel Is (tatusBar#.1anels0#3 Then &checks if status bar panel7 is clicked and if true opens a webpage (ystem.*iagnostics.1rocess.(tart08www.msdn.mcirosoft.com83 ElseIf e.(tatusBar1anel Is (tatusBar#.1anels073 Then &checks if status bar panelA is clicked and if true opens a webpage (ystem.*iagnostics.1rocess.(tart08www.start!bdotnet.com83 End If End (ub 'hen you run the application and click on -(*N you will be taken to -(*N and (tart!bdotnet.com if you click on (tart!bdotnet.

Noti!'1&on Notify Icons display an icon in 'indows (ystem Tray. This is really useful for processes that run in the background and don&t ha!e their own interface. (ince 4B allows us to create 'indows (er!ices 0ser!ices that run in the background and display control panels3 now, we can use these notify icon&s to associate funtionality to windows ser!ices. Bou can also use this icon to associate help with your application, launch another application or anything else which you think can be appropriate. Nota#"e %ro%erties of Notify Icon< 2ontext-enu< @ets:(ets 2ontext menu for the tray icon Icon< @ets:(ets current icon Text< @ets:(ets tooltip text that is displayed when the mouse ho!ers o!er the system tray 4isible< @ets:(ets if the icon is !isible in the windows system tray Noti!' 1&on Event The default e!ent associated with Notify Icon is the -ouse*own e!ent which looks like this in code< 1ri!ate (ub NotifyIcon7Q-ouse*own0By4al sender s (ystem.)bject, By4al e s Q (ystem.'indows."orms.-ouseE!ent rgs3 +andles NotifyIcon7.-ouse*own End (ub Bou can also handle click and double9click e!ents for notify icon. The code sample below works with the click e!ent of the Notify Icon to display a help file. To create a Notify Icon component you need an icon 0.ico3 file to assign to it&s Icon property. If you ha!e an icon then you can use it else you might need to create an icon. Bou can create new icons with 4isual (tudio&s icon designer. To open the icon designer select 1roject9I dd New Item and from the dd New Item dialog select Icon "ile and click open. Bou can use the toolbars that are !isible to design your icon. The Icon *esigner 'indow is displayed below.

$am%"e Co,e *rag a Notify Icon component and a /abel control from the toolbar onto the form. )pen the properties window for the Notify Icon and set the Icon property to the path of the icon and the text property to 8+elp with this "orm8. This is the icon that will be displayed when you run the application. The /abel control is needed to set the help file. (et the text for label as 8I ha!e +elp8. The form in design !iew should look like the image below.

This sample code launches a help file when you click the Icon in (ystem Tray. This sample code assumes that you ha!e a help file, 8+elp.htm8 in the 2< dri!e of your machine. 1ri!ate (ub NotifyIcon#Qclick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles NotifyIcon#.2lick &handling click e!ent of the NotifyIcon +elp.(how+elp0/abel#, 8c<Hhelp.htm83 &using the +elp class and it&s (how+elp method to display a help file End (ub 'hen you run the application, an icon will be !isible in the (ystem Tray and when you click the icon the help file named 8+elp.htm8 will be launched. The image below displays the output from abo!e code.

+rint Dia"ogs 1ro!iding support for 1rinting is one of the common tasks during application de!elopment. The .NET "ramework pro!ides excellent support for 1rinting documents. +rintDo&ument Com%onent In the .NET "ramework, a printed document is represented by the 1rint*ocument component. The 1rint*ocument object encapsulates all the information needed to print a

page. They handle the e!ents and operations of printing. The 1rint*ocument object exposes three properties which are as follows< 1rinter(ettings 1roperty< 2ontains information about the capabilities and settings of the printers. *efault1age(ettings 1roperty< Encapsulates the configuration for printing each printed page. 1rint2ontroller 1roperty< *escribes how each page is guided through the printing process. @ow +rinting Works? 1rinting content is pro!ided directly by the application logic in the .NET "ramework. Bou add a 1rint*ocument object to the project and handle the 1rint1age e!ent which is called e!ery time a new page is to be printed. print job is initiated by the 1rint*ocument&s 1rint method. This starts the print job and raises one or more e!ents. 'hen the print job begins, a Begin1rint e!ent occurs, followed by the 1rint1age e!ent for each page, followed by the End1age e!ent when the job is done. If the print job contains multiple pages, one 1rint1age e!ent will be raised for each page in the job making the 1rint1age e!ent to execute multiple times. The 1rint1age e!ent is the main e!ent in!ol!ed in printing documents. To send content to the printer you must handle this e!ent and pro!ide code to render the content in the 1rint1age e!ent handler. +rintDia"ogs 1rint dialogs are supported by the 1rint*ialog class and they allow us to print the document. To print a document we need to set the *ocument property of the 1rint*ialog to 1rint*ocument object and 1rinter(ettings to 1rinter(ettings object. Bou can print the document by assigning 1rint*ialog object&s 1rinter(ettings property to the 1rinter(ettings property of the 1rint*ocument object and use the 1rint*ocument object&s 1rint method. +ro%erties o! the +rint Dia"og are as !o""ows* llow1rintTofile< @ets:(ets whether the 1rint to file checkbox is enabled. llow(election< @ets:(ets whether the selection radio is enabled. llow(ome1ages< @ets:(ets whether the "rom...To...1age radio button is enabled. *ocument< @ets:(ets the 1rint*ocument used to obtain 1rinter(ettings. 1rinter(ettings< @ets:(ets the 1rinter(ettings dialog box to modify. 1rintTo"ile< @ets:(ets whether the 1rint to file checkbox is enabled. (how+elp< @ets:(ets whether the +elp button is displayed. (howNetwork< @ets:(ets whether the network button is displayed. +rint+reviewDia"og 1rint 1re!iew dialogs are supported by the 1rint1re!iew*ialog class and they allow us to pre!iew the document before printing. Bou can pre!iew a document by

setting the *ocument property of the 1rint1re!iew*ialog object to the 1rint*ocument object. )nce set, the 1rint1re!iew*ialog pro!ides functionality to Eoom, print, to !iew multiple pages of the pre!iew, etc. +rint+reviewContro" 1rint1re!iew control allows to create our own custom pre!iews. They display print pre!iews and you can use it to create your own custom print pre!iew windows. To use this control you need to set the print document to it&s *ocument property. Nota#"e %ro%erties o! the +rint+reviewContro" are as !o""ows* uto\oom< 'hen True 0default3, resiEing the control automatically Eooms to make all contents !isible. 2olumns< @ets:(ets the number of pages displayed horiEontally. =ows< @ets:(ets the number of pages displayed !ertically. (tart1age< @ets:(ets the apge number of the upper left page. \oom< @ets:(ets a !alue specifying how large the pages will appear. +age$etu%Dia"og 1age (etup dialogs are used to specify page details for printing. This dialog allows us to set borders and adjustments, headers and footers, portraits, orientation, etc. Bou use the 1rinter(ettings property of this dialog to get a 1rinter (ettings object that holds settings the user specified. The 1age(etup*ialog exposes a *ocument property that specifies the 1rint*ocument to use. (etting the *ocument property binds the specifed 1rint*ocument to the 1age(etup*ialog and any changes made in this dialog are updated in the 1rinter(ettings property. +rint Dia"ogs /et&s work with print related controls pro!ided by the .NET "ramework. )n a new form drag a 1rint*ialog, 1rint*ocument, 1rint1re!iew2ontrol, 1rint1re!iew*ialog, 1age(etup*ialog, -ain-enu and a =ichtTextBox contol. (elect -ain-enu and In the 8Type +ere8 part, type "ile and under file type 1rint, 1rint1re!iew, 1age(etup and 112ontrol. The menu should look like this<"ile9I1rint, 1rint1re!iew, 1age(etup, 112ontrol. The =ichTextBox control is used to load some text in it which will be ready to print. The "orm in design !iew should look like the image below. Before proceeding further you need to set properties for these dialogs in their properties window. Bou can set these properties at run time if you wish. (etting them at design time will reduce some lines of code. The necessary changes are listed below. "or 1rint*ialog#, set the llow(election and llow(ome1ages properties to True and the *ocument property to 1rint*ocument#.

"or 1rint1re!iew*ialog#, 1age(etup*ialog# and 1rint1re!iew2ontrol#, set the *ocument property to 1rint*ocument# 0for all of them3.

Co,e Imports (ystem.*rawing.1rinting 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm ;=egion 8 'indows "orm *esigner generated code 8 ;End =egion 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e s Q (ystem.E!ent rgs3 +andles -yBase./oad =ichTextBox#.Text J 81rogrammers ha!e undergone a major change in many years of Q programming !arious machines. "or example, what could take days to create an Q

application in other programming languages like 2, 2KK could be done in hours with Q 4isual Basic. 4isual Basic pro!ides many interesting sets of tools to aid us in Q building exciting applications. 4isual Basic pro!ides these tools to make our Q life far more easier because all the real hard code is already written for us.8 &filling the richtextbox with some text that can be used readily End (ub 1ri!ate (ub -enuItem7Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItem7.2lick If 1rint*ialog#.(how*ialog J *ialog=esult.)[ Then &show*ialog method makes the dialog box !isible at run time 1rint*ocument#.1rint03 End If End (ub 1ri!ate (ub -enuItemAQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemA.2lick Try 1rint1re!iew*ialog#.(how*ialog03 2atch es s Exception -essageBox.(how0es.-essage3 End Try End (ub 1ri!ate (ub -enuItemRQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemR.2lick 'ith 1age(etup*ialog# .1age(ettings J 1rint*ocument#.*efault1age(ettings End 'ith Try If 1age(etup*ialog#.(how*ialog J *ialog=esult.)[ Then 1rint*ocument#.*efault1age(ettings J 1age(etup*ialog#.1age(ettings End If 2atch es s Exception -essageBox.(how0es.-essage3 End Try End (ub

1ri!ate (ub -enuItemFQ2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles -enuItemF.2lick Try 1rint1re!iew2ontrol#.*ocument J 1rint*ocument# 2atch es s Exception -essageBox.(how0es.-essage3 End Try End (ub 1ri!ate (ub 1rint*ocument#Q1rint1age0By4al sender s )bject, By4al e sQ (ystem.*rawing.1rinting.1rint1ageE!ent rgs3 +andles 1rint*ocument#.1rint1age &1rint1age is the foundational printing e!ent. This e!ent gets fired for e!ery & page that will be printed (tatic int2urrent2har s IntA7 & declaring a static !ariable to hold the position of the last printed char *im font s New "ont084erdana8, #R3 & initialiEing the font to be used for printing *im 1rint rea+eight, 1rint rea'idth, margin/eft, marginTop s IntA7 'ith 1rint*ocument#.*efault1age(ettings & initialiEing local !ariables that contain the bounds of the printing area rectangle 1rint rea+eight J .1aper(iEe.+eight 9 .-argins.Top 9 .-argins.Bottom 1rint rea'idth J .1aper(iEe.'idth 9 .-argins./eft 9 .-argins.=ight & initialiEing local !ariables to hold margin !alues that will ser!e & as the . and B coordinates for the upper left corner of the printing & area rectangle. margin/eft J .-argins./eft marginTop J .-argins.Top & . and B coordinate End 'ith If 1rint*ocument#.*efault1age(ettings./andscape Then *im intTemp s IntA7 intTemp J 1rint rea+eight 1rint rea+eight J 1rint rea'idth 1rint rea'idth J intTemp & if the user selects landscape mode, swap the printing area height and width End If

*im int/ine2ount s IntA7 J 2Int01rint rea+eight : font.+eight3 & calculating the total number of lines in the document based on the height of & the printing area and the height of the font *im rect1rinting rea s New =ectangle"0margin/eft, marginTop, 1rint rea'idth, 1rint rea+eight3 & initialiEing the rectangle structure that defines the printing area *im fmt s New (tring"ormat0(tring"ormat"lags./ine/imit3 &instantiating the (tring"ormat class, which encapsulates text layout information *im int/ines"illed, int2hars"itted s IntA7 e.@raphics.-easure(tring0-id0=ichTextBox#.Text, int2urrent2har K #3, font,Q New (iEe"01rint rea'idth, 1rint rea+eight3, fmt, int2hars"itted, int/ines"illed3 & calling -easure(tring to determine the number of characters that will fit in & the printing area rectangle e.@raphics.*raw(tring0-id0=ichTextBox#.Text, int2urrent2har K #3, font,Q Brushes.Black, rect1rinting rea, fmt3 & print the text to the page int2urrent2har KJ int2hars"itted &ad!ancing the current char to the last char printed on this page If int2urrent2har W =ichTextBox#.Text./ength Then e.+as-ore1ages J True &+as-ore1ages tells the printing module whether another 1rint1age e!ent should be fired Else e.+as-ore1ages J "alse int2urrent2har J % End If End (ub End 2lass The abo!e code will throw exceptions if you don&t ha!e a printer attached to your machine. 22+ Basi&s 4isual Basic was )bject9Based, 4isual Basic .NET is )bject9)riented, which means that it&s a true )bject9)riented 1rogramming /anguage. 4isual Basic .NET

supports all the key ))1 features like 1olymorphism, Inheritance, bstraction and Encapsulation. It&s worth ha!ing a brief o!er!iew of ))1 before starting ))1 with 4B. Wh' 2#3e&t 2riente, a%%roa&h? major factor in the in!ention of )bject9)riented approach is to remo!e some of the flaws encountered with the procedural approach. In ))1, data is treated as a critical element and does not allow it to flow freely. It bounds data closely to the functions that operate on it and protects it from accidental modification from outside functions. ))1 allows decomposition of a problem into a number of entities called objects and then builds data and functions around these objects. major ad!antage of ))1 is code reusability. (ome important features of )bject )riented programming are as follows<

Emphasis on data rather than procedure 1rograms are di!ided into )bjects *ata is hidden and cannot be accessed by external functions )bjects can communicate with each other through functions New data and functions can be easily added whene!er necessary "ollows bottom9up approach

Con&e%ts o! 22+*

)bjects 2lasses *ata bstraction and Encapsulation Inheritance 1olymorphism

Brie!"' on Con&e%ts* 2#3e&ts Objects are the basic run9time entities in an object9oriented system. 1rogramming problem is analyEed in terms of objects and nature of communication between them. 'hen a program is executed, objects interact with each other by sending messages. *ifferent objects can also interact with each other without knowing the details of their data or code. C"asses class is a collection of objects of similar type. )nce a class is defined, any number of objects can be created which belong to that class.

Data .#stra&tion an, En&a%su"ation Abstraction refers to the act of representing essential features without including the background details or explanations. 2lasses use the concept of abstraction and are defined as a list of abstract attributes. (toring data and functions in a single unit 0class3 is encapsulation. *ata cannot be accessible to the outside world and only those functions which are stored in the class can access it. 1nheritan&e Inheritance is the process by which objects can ac6uire the properties of objects of other class. In ))1, inheritance pro!ides reusability, like, adding additional features to an existing class without modifying it. This is achie!ed by deri!ing a new class from the existing one. The new class will ha!e combined features of both the classes. +o"'mor%hism Polymorphism means the ability to take more than one form. n operation may exhibit different beha!iors in different instances. The beha!ior depends on the data types used in the operation. 1olymorphism is extensi!ely used in implementing Inheritance. .,vantages o! 22+ )bject9)riented 1rogramming has the following ad!antages o!er con!entional approaches<

))1 pro!ides a clear modular structure for programs which makes it good for defining abstract datatypes where implementation details are hidden and the unit has a clearly defined interface. ))1 makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones. ))1 pro!ides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for de!eloping graphical user interfaces.

Constru&tors
constructor is a special member function whose task is to initialiEe the objects of it&s class. constructor is in!oked whene!er an object of it&s associated class is created. If a class contains a constructor, then an object created by that class will be initialiEed automatically. 'e pass data to the constructor by enclosing it in the parentheses following the class name when creating an object. In 4isual Basic we create

constructors by adding a (ub procedure name New to a class. The following code demonstrates the use of constructors in 4isual Basic. -odule -odule# (ub -ain03 *im con s New 2onstructor0#%3 'rite/ine0con.display033 &storing a !alue in the constructor by passing a !alue0#%3 and calling it with the &display method =ead03 End (ub End -odule 1ublic 2lass 2onstructor 1ublic x s Integer 1ublic (ub New0By4al !alue s Integer3 &constructor x J !alue &storing the !alue of x in constructor End (ub 1ublic "unction display03 s Integer =eturn x &returning the stored !alue End "unction End 2lass Destru&tors *estructors run when an object is destroyed. 'ithin a destructor we can place code to clean up the object after it is used. 'e use "inaliEe method in 4isual Basic for this and the "inaliEe method is called automatically when the .NET runtime determines that the object is no longer re6uired. 'hen working with destructors we need to use the o!errides keyword with "inaliEe method as we will o!erride the "inaliEe method built into the )bject class. 'e normally use "inaliEe method to deallocate resources and inform other objects that the current object is going to be destroyed. The following code demonstrates the use of "inaliEe method. -odule -odule# (ub -ain03

*im obj s New *estructor03 End (ub End -odule 1ublic 2lass *estructor 1rotected )!errides (ub "inaliEe03 'rite08hello83 =ead03 End (ub End 2lass 'hen you run the abo!e code, the word and object, obj of class, destructor is created and 8+ello8 is displayed. 'hen you close the *)( window, obj is destro

1nheritan&e
key feature of ))1 is reusability. It&s always time sa!ing and useful if we can reuse something that already exists rather than trying to create the same thing again and again. =eusing the class that is tested, debugged and used many times can sa!e us time and effort of de!eloping and testing it again. )nce a class has been written and tested, it can be used by other programs to suit the program&s re6uirement. This is done by creating a new class from an existing class. The process of deri!ing a new class from an existing class is called Inheritance. The old class is called the base class and the new class is called deri!ed class. The deri!ed class inherits some or e!erything of the base class. In 4isual Basic we use the Inherits keyword to inherit one class from other. The general form of deri!ing a new class from an existing class looks as follows< 1ublic 2lass )ne 999 999 End 2lass 1ublic 2lass Two Inherits )ne 999 999 End 2lass >sing Inheritance we can use the !ariables, methods, properties, etc, from the base class and add more functionality to it in the deri!ed class. The following code demonstrates the process of Inheritance in 4isual Basic. Imports (ystem.2onsole

-odule -odule# (ub -ain03 *im ss s New Two03 'rite/ine0ss.sum033 =ead03 End (ub End -odule 1ublic 2lass )ne &base class 1ublic i s Integer J #% 1ublic j s Integer J 7% 1ublic "unction add03 s Integer =eturn i K j End "unction End 2lass 1ublic 2lass Two LnbspInherits )ne &deri!ed class. class two inherited from class one 1ublic k s Integer J #%% 1ublic "unction sum03 s Integer &using the !ariables, function from base class and adding more functionality =eturn i K j K k End "unction End 2lass

)utput of abo!e code is sum of i, j, k as shown in the image below.

+o"'mor%hism
1olymorphism is one of the crucial features of ))1. It means 8one name, multiple forms8. It is also called as )!erloading which means the use of same thing for different purposes. >sing 1olymorphism we can create as many functions we want with one function name but with different argument list. The function performs different operations based on the argument list in the function call. The exact function to be in!oked will be determined by checking the type and number of arguments in the function. The following code demonstrates the implementation of 1olymorphism. -odule -odule# (ub -ain03 *im two s New )ne03 'rite/ine0two.add0#%33 &calls the function with one argument 'rite/ine0two.add0#%, 7%33 &calls the function with two arguments 'rite/ine0two.add0#%, 7%, A%33 &calls the function with three arguments =ead03 End (ub End -odule

1ublic 2lass )ne 1ublic i, j, k s Integer 1ublic "unction add0By4al i s Integer3 s Integer &function with one argument =eturn i End "unction 1ublic "unction add0By4al i s Integer, By4al j s Integer3 s Integer &function with two arguments =eturn i K j End "unction 1ublic "unction add0By4al i s Integer, By4al j s Integer, By4al k s Integer3 s Integer &function with three arguments =eturn i K j K k End "unction End 2lass )utput of the abo!e code is shown in the image below. 9) 8) ()

1nter!a&es
Interfaces allow us to create definitions for component interaction. They also pro!ide another way of implementing polymorphism. Through interfaces, we specify methods that a component must implement without actually specifying how the method is implemented. 'e just specify the methods in an interface and lea!e it to the class to implement those methods. 4isual Basic .NET does not support multiple inheritance directly but using interfaces we can achie!e multiple inheritance. 'e use the Interface keyword to create an interface and implements keyword to implement the interface. )nce you create an interface you need to implement all the methods specified in that interface. The following code demonstrates the use of interface. Imports (ystem.2onsole -odule -odule# (ub -ain03 *im )ne)bj s New )ne03

*im Two)bj s New Two03 &creating objects of class )ne and Two )ne)bj.disp03 )ne)bj.multiply03 Two)bj.disp03 Two)bj.multiply03 &accessing the methods from classes as specified in the interface End (ub End -odule 1ublic Interface Test &creating an Interface named Test (ub disp03 "unction -ultiply03 s *ouble &specifying two methods in an interface End Interface 1ublic 2lass )ne LnbspImplements Test &implementing interface in class )ne 1ublic i s *ouble J #7 1ublic j s *ouble J #7.#Y (ub disp03 Implements Test.disp &implementing the method specified in interface 'rite/ine08sum of iKj is8 L i K j3 =ead03 End (ub 1ublic "unction multiply03 s *ouble Implements Test.-ultiply &implementing the method specified in interface 'rite/ine0i V j3 =ead03 End "unction End 2lass 1ublic 2lass Two LnbspImplements Test &implementing the interface in class Two 1ublic a s *ouble J 7% 1ublic b s *ouble J A7.#Y

(ub disp03 Implements Test.disp 'rite/ine08'elcome to Interfaces83 =ead03 End (ub 1ublic "unction multiply03 s *ouble Implements Test.-ultiply 'rite/ine0a V b3 =ead03 End "unction End 2lass )utput of abo!e code is the image below. $um o! iI3 is:;.9C 9;(.); We"&ome to 1nter!a&es (;8.;

.#stra&t C"asses
n abstract class is the one that is not used to create objects. n abstract class is designed to act as a base class 0to be inherited by other classes3. bstract class is a design concept in program de!elopment and pro!ides a base upon which other classes are built. bstract classes are similar to interfaces. fter declaring an abstract class, it cannot be instantiated on it&s own, it must be inherited. /ike interfaces, abstract classes can specify members that must be implemented in inheriting classes. >nlike interfaces, a class can inherit only one abstract class. bstract classes can only specify members that should be implemented by all inheriting classes. Creating .#stra&t C"asses In 4isual Basic .NET we create an abstract class by using the -ustInherit keyword. n abstract class like all other classes can implement any number of members. -embers of an abstract class can either be )!erridable 0all the inheriting classes can create their own implementation of the members3 or they can ha!e a fixed implementation that will be common to all inheriting members. bstract classes can also specify abstract members. /ike abstract classes, abstract members also pro!ide no details regarding their implementation. )nly the member type, access le!el, re6uired parameters and return type are specified. To declare an abstract member we use the -ust)!erride keyword. bstract members should be declared in abstract classes.

1m%"ementing .#stra&t C"ass 'hen a class inherits from an abstract class, it must implement e!ery abstract member defined by the abstract class. Implementation is possible by o!erriding the member specified in the abstract class. The following code demonstrates the declaration and implementation of an abstract class. -odule -odule# 1ublic -ustInherit 2lass bstract2lass &declaring an abstract class with -ustInherit keyword 1ublic -ust)!erride "unction dd03 s Integer 1ublic -ust)!erride "unction -ul03 s Integer &declaring two abstract members with -ust)!erride keyword End 2lass 1ublic 2lass bstract)ne LnbspInherits bstract2lass &implementing the abstract class by inheriting *im i s Integer J 7% *im j s Integer J A% &declaring two integers 1ublic )!errides "unction dd03 s Integer =eturn i K j End "unction &implementing the add method 1ublic )!errides "unction -ul03 s Integer =eturn i V j End "unction &implementing the mul method End 2lass (ub -ain03 *im abs s New bstract)ne03 &creating an instance of bstract)ne 'rite/ine08(um is8 L 8 8 L abs. dd033 'rite/ine08-ultiplication is8 L 8 8 L abs.-ul033 &displaying output =ead03 End (ub End -odule

The output of abo!e code is the image below. $um is ?) 5u"ti%"i&ation is ())

$tru&tures
(tructures can be defined as a tool for handling a group of logically related data items. They are user9defined and pro!ide a method for packing together data of different types. (tructures are !ery similar to 2lasses. /ike 2lasses, they too can contain members such as fields and methods. The main difference between classes and structures is, classes are reference types and structures are !alue types. In practical terms, structures are used for smaller lightweight objects that do not persist for long and classes are used for larger objects that are expected to exist in memory for long periods. 'e declare a structure in 4isual Basic .NET with the (tructure keyword. Va"ue T'%es an, Re!eren&e T'%es 4alue Types and =eference Types belong to pplication data memory and the difference between them is the way !ariable data is accessed. 'e will ha!e a brief o!er!iew about them. Va"ue T'%es In 4B .NET we use the *im statement to create a !ariable that represents a !alue type. "or example, we declare a integer !ariable with the following statement< Dim 0 as 1nteger. The statement tells the run time to allocate the appropriate amount of memory to hold an integer !ariable. The statement creates a !ariable but does not assign a !alue to it. 'e assign a !alue to that !ariable like this< 0>??. 'hen a !ariable of !alue type goes out of scope, it is destroyed and it&s memory is reclaimed. Re!eren&e T'%es 2reating a !ariable of reference type is a two9step process, declare and instantiate. The first step is to declare a !ariable as that type. "or example, the following statement Dim Form9 as new $'stem.Win,ows.Forms.Form tells the run time to set enough memory to hold a "orm !ariable. The second step, instantiation, creates the object. It looks like this in code< Form9>New $'stem.Win,ows.Forms.Form. !ariable of reference type exists in two memory locations and that&s why when that !ariable goes out of scope, the reference to that object is destroyed but the object itself is not destroyed. If any other references to that object exist, the object remains intact. If no references exist to that object then it is subject to garbage collection. Co,e !or Creating a $tru&ture

The following code creates a (tructure named Employee with fi!e fields of different data types. -odule -odule# (tructure Employee &declaring a structure named Employee *im EmpName s (tring *im Emp*esignation s (tring *im Emp2ity s (tring *im Emp(al s *ouble *im EmpId s Integer &declaring fi!e fields of different data types in the structure End (tructure (ub -ain03 *im san s New Employee03 &creating an instance of Employee san.EmpName J 8(andeep8 san.Emp*esignation J 8(oftware *e!eloper8 san.Emp2ity J 8(ydney8 san.Emp(al J ?%%%% san.EmpId J 7Y%Y &assigning !alues to member !ariables 'rite/ine08EmpName8 K 8 8 K san.EmpName3 'rite/ine08Emp*esignation8 K 8 8 K san.Emp*esignation3 'rite/ine08Emp2ity8 K 8 8 K san.Emp2ity3 'rite/ine08Emp(alary8 K 8 8 K san.Emp(al.To(tring3 'rite/ine08EmpI*8 K 8 8 K san.EmpId.To(tring3 &accessing member !ariables with the period:dot operator =ead03 End (ub End -odule 6ser Contro"s >ser 2ontrols are the controls which are created by the user and they are based on the class (ystem.'indows."orms.>ser2ontrol. /ike standard controls, user controls support properties, methods and e!ents. )nce a user control is created it can be added to any form or any number of forms like all other controls. Creating a 6ser Contro" To create a user control select "ile9INew9I1roject9I4isual Basic 1rojects and select 'indows 2ontrol /ibrary from the templates and click )[. lternati!ely, you can

add user control to the existing project by selecting 1roject9I dd >ser 2ontrol. The image below displays the new project dialogue to add a >ser 2ontrol project.

The form that opens after clicking )[ looks like the image below. It looks similar to a normal form.

Creating a 6ser Contro" with E0am%"e *rag a /abel and a TextBox control from the toolbox onto the new user control form. The image below displays that.

*ouble9click the user control form to open it&s code behind file. In the code behind file type the following code below the /oad e!ent 0under End (ub3 of >ser2ontrol# to set the property of the user control which is being created.

1ublic 1roperty sanText03 s (tring @et sanText J TextBox#.Text End @et (et0By4al 4alue s (tring3 TextBox#.Text J 4alue End (et End 1roperty 1ublic 1roperty san/bl03 s (tring @et san/bl J /abel#.Text End @et (et0By4al 4alue s (tring3 /abel#.Text J 4alue End (et End 1roperty The abo!e code implements the sanText03 and san/bl03 properties with a property get:set pair. )nce typing the code is done build the solution using Build9IBuild (olution from the main menu to create the .dll 0*ynamic /ink /ibrary3 file to which we refer to. The dll file also makes this user control a!ailable to other projects. fter finishing building the solution we next need to add this user control to the toolbox to make it a!ailable to other projects and forms. To do that, open a windows form or use an existing form. =ight9click on the 'indows "orm tab section on the toolbox and click on 2ustomiEe Toolbox as shown in the image below.

2licking on 2ustomiEe Toolbox opens 82ustomiEe Toolbox8 dialogue box as shown in the image below.

)n this window select the .NET "ramework components tab which displays a list. 2lick browse to add the dll of the user control we created and select the dll file from the bin directory of the 'indows 2ontrol library project. )nce that is done, click )[. The dll of the user control gets added to the .NET "ramework 2omponents. (elect that and click )[. The user control which we created gets added to the toolbox. Now this control can be used like other controls in the toolbox. lternati!ely, the user control can be added to the toolbox in another way. To do that, right9click on the =eferences item in the (olution Explorer window and select dd =eference which opens the dd =eference dialogue box. (elect the projects tab and

double9click the >ser 2ontrol item. That adds item to the selected components box at the bottom of the dialog. click )[ to finish. 6sing the 6ser Contro" The user control, >ser2ontrol## which we created can be added to any form like all other controls. )pen a new form and drag this user control from toolbox to the form. *rag a Button from the toolbox and place that on the form. *ouble9click Button to open it&s 2lick e!ent. 1lace the following code in the 2lick e!ent of the Button< 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4alQ e s (ystem.E!ent rgs3 +andles Button#.2lick -essageBox.(how08TextBox8 L >ser2ontrol##.sanText033 -essageBox.(how08/abel#8 L >ser2ontrol##.san/bl033 End (ub
Bun the code and enter some te-t in the Te-tBo-. Dhen you c#ic? the Button/ the te-t entered in the Te-tBo- is disp#ayed in a 2essageBo-. ThatCs the @ay User Contro#s are used a$ter they are created.

1nherting Contro"s )ne of the easiest ways to create a new control is to inherit from a preexisting control. 'hen inheriting from an existing control, the newly created control contains all the functionality of the base control but can also ser!e as a base for adding new functionality. In addition to ha!ing all the functionality of the base control an inherited control also inherits the !isual representation of the base control. "or example, you can inherit from a TextBox control and implement code to change its appearance. >nless sealed 0NotInheritable3, most 'indows 2ontrols can be used as a base class for inheritance. Inheriting from an existing control is the most easiest way of creating a new control. Bou can choose this method if you want to replicate an exisiting windows control and want to add more functionality to it. Bou can also use this method if you want to ha!e all the functionality of the existing control but want to pro!ide a new look and feel. To create a new Inherited control you must specify a 'indows "orm control as a base class for this control. The following sample code creates a textbox that accepts only numbers as user input.To implement that functionality you must o!erride the )n[ey1ress method as shown below. 1ublic 2lass Number)nlyBox Inherits (ystem.'indows."orms.TextBox

1rotected )!errides (ub )n[ey1ress0By4al e as [ey1ressE!ent rgs3 If 2har.IsNumber0e.[ey2har3J"alse Then e.handledJTrue End If End (ub End 2lass Fi"es in VB .NET Working with Fi"es "ile handling in 4isual Basic is based on (ystem.I) namespace with a class library that supports string, character and file manipulation. These classes contain properties, methods and e!ents for creating, copying, mo!ing, and deleting files. (ince both strings and numeric data types are supported, they also allow us to incorporate data types in files. The most commonly used classes are "ile(tream, Binary=eader, Binary'riter, (tream=eader and (tream'riter. Fi"e$tream C"ass This class pro!ides access to standard input and output files. 'e use the members of "ile ccess, "ile-ode and "ile(hare Enumerations with the constructors of this class to create or open a file. fter a file is opened it&s "ile(tream object can be passed to the Binary =eader, Binary'riter, (treamreader and (tream'riter classes to work with the data in the file. 'e can also use the "ile(tream(eek method to mo!e to !arious locations in a file which allows to break a file into records each of the same length. $treamRea,er an, $treamWriter C"ass The (tream=eader and (tream'riter classes enables us to read or write a se6uential stream of characters to or from a file. Binar'Rea,er an, Binar'Writer C"ass The Binary=eader and Binary'riter classes enable us to read and write binary data, raw %&s and #&s, the form in which data is stored on the computer. The following examples puts some code to work with textual data using "ile(tream and (tream=eader and (tream'riter classes. Co,e to &reate a Fi"e Imports (ystem.I)

&Name(pace re6uired to be imported to work with files 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al eQ s (ystem.E!ent rgs3 +andles -yBase./oad *im fs as New "ile(tream08file.doc8, "ile-ode.2reate, "ile ccess.'rite3 &declaring a "ile(tream and creating a word document file named file with &access mode of writing *im s as new (tream'riter0fs3 &creating a new (tream'riter and passing the filestream object fs as argument s.Base(tream.(eek0%,(eek)rigin.End3 &the seek method is used to mo!e the cursor to next position to a!oid text to be &o!erwritten s.'rite/ine08This is an example of using file handling concepts in 4B .NET.83 s.'rite/ine08This concept is interesting.83 &writing text to the newly created file s.2lose03 &closing the file End (ub End 2lass The default location where the files we create are sa!ed is the bin directory of the 'indows pplication with which we are working. The image below displays that.

Co,e to &reate a !i"e an, rea, !rom it

*rag a Button and a =ichTextBox control onto the form. 1aste the following code which is shown below. Imports (ystem.I) &Name(pace re6uired to be imported to work with files 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm 1ri!ate (ub Button#Q2lick0By4al....., By!al.....3+andles Button#.2lick *im fs as New "ile(tream08file.doc8, "ile-ode.2reate, "ile ccess.'rite3 &declaring a "ile(tream and creating a document file named file with &access mode of writing *im s as new (tream'riter0fs3 &creating a new (tream'riter and passing the filestream object fs as argument s.'rite/ine08This is an example of using file handling concepts in 4B .NET.83 s.'rite/ine08This concept is interesting.83 &writing text to the newly created file s.2lose03 &closing the file fsJNew "ile(tream08file.doc8,"ile-ode.)pen,"ile ccess.=ead3 &declaring a "ile(tream to open the file named file.doc with access mode of reading *im d as new (tream=eader0fs3 &creating a new (tream=eader and passing the filestream object fs as argument d.Base(tream.(eek0%,(eek)rigin.Begin3 &(eek method is used to mo!e the cursor to different positions in a file, in this code, to &the beginning while d.peek03I9# &peek method of (tream=eader object tells how much more data is left in the file =ichTextbox#.Text LJ d.read/ine03 &displaying text from doc file in the =ichTextBox End while d.close03 End (ub

The image below displays output of the abo!e code.

Fi"es in VB .NET Working with Dire&tories 'e will work with the "ile and *irectory classes in this section. 'e will create a directory and copy a file into the newly created directory. Fi"e C"ass The "ile class in 4B .NET allows us to work with files, allowing to copy, delete and create files. Dire&tor' C"ass The *irectory class in 4B .NET allows us to create and work with "olders:*irectories. 'ith this class we can create, edit and delete folders and also maintain dri!es on the machine. Co,e to work with Fi"e an, Dire&tor' C"ass The following code will create a directory and copy a file into that new directory. To create a new directory we should use the *irectory class&s 2reate*irectory method. *rag two Button&s 0Button#, Button73, a TextBox and a )pen"ile*ialog control from the toolbar onto the "orm. 'e will use the TextBox to specify a location to create the *irectory when Button# is clicked and the )pen"ile*ialog control to open a file and

copy it into the newly created *irectory when Button7 is clicked. The namespace to be imported is (ystem.I). The code for that looks like this< Imports (ystem.I) 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm &'indows "orm *esigner @enerated 2ode 1ri!ate (ub "orm#Q/oad0By4al sender s (ystem.)bject, By4al e Q s (ystem.E!ent rgs3 +andles -yBase./oad End (ub 1ri!ate (ub Button#Q2lick0By4al sender s (ystem.)bject, By4al e sQ (ystem.E!ent rgs3 +andles Button#.2lick Try *irectory.2reate*irectory0TextBox#.Text3 &2reating a directory by specifying a path in the TextBox, of the form c<Hexamples &Instead of using a TextBox you can directly type the location of the directory like this &*irectory.2reate*irectory08c<Hexamples83 2atch End Try -sgBox08*one83 End (ub 1ri!ate (ub Button7Q2lick0By4al sender s (ystem.)bject, By4al e s Q (ystem.E!ent rgs3 +andles Button7.2lick Try If )pen"ile*ialog#.(how*ialog WI *ialog=esult.2ancel Then "ile.2opy0)pen"ile*ialog#."ileName, TextBox#.Text L 8H8 L Q )pen"ile*ialog#."ileName.(ubstring0)pen"ile*ialog#."ileName./astIndex)f08H8333 &The abo!e line of code uses )pen"ile*ialog control to open a dialog box where you &can select a file to copy into the newly created directory End If 2atch End Try -sgBox08"ile 2opied (uccessfully83 End (ub End 2lass That&s all it takes to create a directory and copy a file into the newly created directory in 4B.NET. The image below shows output from abo!e code.

The image below shows the directory I created and the file I copied to the new directory using the code abo!e.

5u"tithrea,ing -ultithreading gi!es programs the ability to do se!eral things at a time. Each stream of execution is called a thread. -ultithreading is used to di!ide lengthy tasks into different segments that would otherwise abort programs. Threads are mainly used to utiliEe the processor to a maximum extent by a!oiding it&s idle time. Threading lets a program seem as if it is executing se!eral tasks at once. 'hat actually happens is, the time gets di!ided by the computer into parts and when a new thread starts, that thread gets a portion of the di!ided time. Threads in 4B .NET are based on the namespace (ystem.Threading. Creating Threa,s To create threads lets work with an example. The following example is an extract from (te!en +olEner&s reference, 1rogramming with 4isual Basic.NET9 Black Book. )pen a new windows application and name it as Thread and add a class named count# using the 1rojects9I dd 2lass item. This class will count from # to a specified !alue in a data member named 2ountTo when you call the 2ount method. fter the count has reached the !alue in 2ountTo, a "inished2ounting e!ent will occur. The code for the 2ount class looks like this< 1ublic 2lass 2ount# 1ublic 2ountTo as Integer 1ublic e!ent "inished2ounting0By 4al Number)f-atches as Integer3 (ub 2ount03 *im ind,tot as Integer totJ% "or indJ# to 2ountTo totKJ# Next ind =aiseE!ent "inished2ounting0tot3 &makes the "inished2ounting e!ent to occur End (ub End 2lass /et&s use this class with a new thread. @et back to the main form and create an object of this class, counter#, and a new thread, Thread#. The code looks like this< 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm *im counter# as new 2ount#03 *im Thread# as New (ystem.Threading.Thread0 ddress of counter.2ount3

*rag a Button and two TextBoxes 0TextBox#, TextBox73 onto the form. Enter a number in TextBox#. The reason for entering a number in textbox is to allow the code to read the !alue specified in TextBox# and display that !alue in TextBox7, with threading. The code for that looks like this< 1ublic 2lass "orm# Inherits (ystem.'indows."orms."orm *im counter# as new 2ount#03 *im Thread# as New (ystem.Threading.Thread0 ddress of counter.2ount3 1ri!ate (ub Button#Q2lick0By4al sender as (ystem.)bject, By4al e as (ystem.E!ent rgs3Q +andles Button#.2lick TextBox7.TextJ8 8 counter#.2ountToJTextBox#.Text dd+andler counter#."inished2ounting, ddress)f"inished2ountingE!ent+andler &adding handler to handle "inished2ounting E!ent Thread#.(tart03 &starting the thread End (ub (ub "inished2ountingE!ent+andler0By4al 2ount as Integer3 &"inished2ountingE!ent+andler TextBox7.TextJ2ount End (ub The result of the abo!e code displays the !alue entered in TextBox#, in TextBox7 with the difference being the Thread counting the !alue from # to the !alue entered in TextBox#. $us%en,ing a Threa, Threads can be suspended. (uspending a thread stops it temporarily. 'orking with the example in the pre!ious section, add a new button Button7 to the main form. 'hen this button is clicked the thread is suspended. The code for that looks like this< 1ri!ate (ub Button7Q2lick0By4al sender as (ystem.)bject, By4al e as (ystem.E!ent rgs3Q +andles Button7.2lick Thread#.(uspend03 End (ub Resuming a Threa,

Threads can be resumed after they are suspended. 'ith the example abo!e, add a new button ButtonA to the main form. 'hen this button is clicked the thread is resumed from suspension. The code for that looks like this< 1ri!ate (ub ButtonAQ2lick0By4al sender as (ystem.)bject, By4al e as (ystem.E!ent rgs3Q +andles ButtonA.2lick Thread#.=esume03 End (ub 5aking a Threa, $"ee% Threads can be made to sleep which means that they can be suspended o!er a specific period of time. (leeping a thread is achie!ed by passing the time 0in milliseconds,#:#%%% of a second3 to the thread&s sleep method. 'ith the example abo!e, add a new button ButtonR to the main form. 'hen this button is clicked the thread is stopped. The code for that looks like this<

1ri!ate (ub ButtonRQ2lick0By4al sender as (ystem.)bject, By4al e as (ystem.E!ent rgs3Q +andles ButtonR.2lick Thread#.(leep0#%%:#%%%3 End (ub $to%%ing a Threa, Threads can be stopped with it&s abort method. 'ith the example abo!e, add a new button ButtonF to the main form. 'hen this button is clicked the thread is stopped. The code for that looks like this< 1ri!ate (ub ButtonFQ2lick0By4al sender as (ystem.)bject, By4al e as (ystem.E!ent rgs3Q +andles ButtonF.2lick Thread#. bort03 End (ub Threa, +riorities Threads can also be assigned priority for execution. Thread priority can be set by the thread&s 1riority property and assigning a !alue from predefined Thread 1riority enumeration.

Va"ues !or Threa, +riorit'* bo!e Normal 9I @i!es thread higher priority Below Normal 9I@i!es thread lower priority Normal 9I @i!es thread normal priority /owest 9I @i!es thread lowest priority +ighest 9I @i!es thread highest priority 'orking with the abo!e example, add a new button Button? to the main form. 'hen this button is clicked the thread is assigned +ighest priority .The code for that looks like this< 1ri!ate (ub Button?Q2lick0By4al sender as (ystem.)bject, By4al e as (ystem.E!ent rgs3Q +andles Button?.2lick Thread#.1riorityJ(ystem.Threading.Thread1riority.+ighest &setting +ighest priority for the thread End (ub "or more information on Threads please refer to -(*N. *eploying pplications )nce an application is de!eloped and if we want to distribute that application, we need to deploy that. *eployment is the process where we create an executable file which can be installed on any machine where the application can run. 'e can use the built9in deployment feature that comes with 4isual Basic to create a 'indows Installer file 9 a .msi file for the purpose of deploying applications. /et&s look at the process with an example. /et&s assume we ha!e a form with a TextBox and a Button. 'hen the Button is clicked the TextBox should display 8This application is *eployed8. /et&s name this application as *eploy. The code for the click e!ent of the Button looks like this< 1ri!ate (ub Button#Q2lick0By 4al sender as (ystem.)bject, By 4al eQ as (ystem.E!ent rgs3+andles Button#.2lick TextBox#.TextJ8This application is *eployed8 End (ub Next, we need to create an executable 0exe3 file for this application. To do that select Build9IBuild from the main menu which builds *eploy.exe. Next, we need to create an installer file for *eploy 0which is the example3 which is a file with .msi extension. To do that, select "ile9I dd 1roject9INew 1roject which opens the new project dialogue. (elect 8(etup and *eployment 1rojects8 icon in the projects type box and (etup 'iEard in the templates box. It looks like the image below.

2lick )[ to open the (etup 'iEard. The (etup wiEard window looks like the image below.

2lick next on the abo!e pane to take you to second pane in the 'iEard. The new pane allows us to create deployment projects both for 'indows and 'eb pplications. +ere, select the radio button which says 82reate a setup for 'indows pplication8 as this

is deploying a windows application and click next. It looks like the image below.

2licking next opens a new pane which has options like *eploying only primary output from the project or both the project and source code or content files. 2heck the checkbox which you want, in this case check the checkbox that says 81rimary )utput from *eploy8 and click next. It looks like the image below.

2licking next opens a new pane which asks if you want any additional files to be added. If you wish, you can include other files, like an icon for the application. In this example don&t include any files and click next. It looks like the image below.

*oing that brings up the last pane of the (etup 'iEard which looks like the image below. 2lick "inish on this pane.

2licking finish opens up a "ile (ystem window which looks like the image below.

This window allows us to create shortcuts to the application on the desktop and in our 1rograms -enu. To create a shortcut, right9click on the folder 8>ser&s *esktop8 and select 82reate (hortcut to >ser&s *esktop8 . =ename the shortcut to 8*eployment8. If we want a shortcut to the application from our 1rograms -enu, right9click on 8>ser&s 1rogram -enu8 folder and select 82reate (hortcut to >ser&s 1rogram -enu8 . =ename the shortcut to 8*eployment8. )nce you are finished with it, click on 8 pplication "older8 and open it&s properties. In the properties window set the property 8 lways 2reate8 to True. (et the same for 8>ser&s *esktop8 and 8>ser&s 1rograms -enu8 folders. If you want any additional information to include with the set9up project, like the manufacturer, author etc, click on (etup# project and open it&s properties. Bou can set additional information here. )nce your are done with it build the project by right9clicking on (etup# and selecting Build. This builds the application. The setup file is created in the debug folder of (etup# project. De%"o'ing the .%%"i&ation To deploy the application we need to copy (etup#.msi file to the target machine. )nce copying is done,

double9click that file which opens the 'indows Installer which is a new window which says 8'elcome to (etup# (etup 'iEard8. It looks like the image below 0mine was (etupY, yours will be (etup#3.

2lick next to mo!e to next window which allows us to specify the location where the application should be installed. It looks like the image below.

(elect the location for installation and click next. 2licking next installs the application. The confirmation window looks like the image below.

Now, double9click the newly installed *eployment.exe file to run and get the desired result. Bou can select that from your 1rograms -enu or *esktop. That completes the process of *eploying pplications. -ake sure the Target -achine on which the application will be installed supports 'indows Installer and .NET "ramework.

You might also like