0% found this document useful (0 votes)
101 views148 pages

فيجوال

This document provides an introduction and overview of VB.NET, including its audience, the .NET framework, and an example "Hello World" VB.NET program. It discusses VB.NET as a modern, object-oriented language that combines the power of the .NET framework with the productivity of Visual Basic. It also briefly describes the integrated development environments available for writing VB.NET programs.

Uploaded by

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

فيجوال

This document provides an introduction and overview of VB.NET, including its audience, the .NET framework, and an example "Hello World" VB.NET program. It discusses VB.NET as a modern, object-oriented language that combines the power of the .NET framework with the productivity of Visual Basic. It also briefly describes the integrated development environments available for writing VB.NET programs.

Uploaded by

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

VB.

NET

I
VB.
NET

Aboutt
heTut
ori
al

VB.Netisasimple,moder n,obj
ect-
orientedcomputerpr
ogrammi
nglanguagedevel
opedby
Microsoftt
ocombi nethepowerof. NETFr ameworkandthecommonlanguager
unti
mewith
theproducti
vi
tybenefi
tsthatarethehallmarkofVi
sualBasi
c.

Thi
stut
ori
alwil
lteachyoubasi
cVB.Netpr
ogrammingandwi l
lal
sot
akey
out
hroughv
ari
ous
adv
ancedconceptsrel
atedt
oVB.Netpr
ogramminglanguage.

Audi
ence

Thistutor
ialhasbeenpr epar
edforthebegi nner
stohel pthem under standbasicVB.Net
progr
ammi ng.Aftercompleti
ngthi
stutori
al,youwillfi
ndy ourselfatamoder at
elevelof
exper
tisei
nVB. Netprogr
ammi ngf
rom wherey oucantakeyourselftonextlev
els.

The.
NetFr
amewor
k

The.Netframewor
kisar
evol
uti
onar
ypl
atf
ormt
hathel
psy
out
owr
it
ethef
oll
owi
ngt
ypesof
appl
i
cations:

• Wi
ndowsappl
i
cat
ions

• Webappl
i
cat
ions

• Webser
vices
The.Netframeworkappli
cat
ionsar
emul t
i-
plat
form appl
icat
ions.Thef r
amewor khasbeen
desi
gnedinsuchawayt hati
tcanbeusedfrom anyofthefol
lowinglanguages:
Visual
Basic,
C#,C++,Jscri
pt,
andCOBOL,etc.

Al
lthesel
anguagescanaccesst
hef
ramewor
kaswel
lascommuni
cat
ewi
theachot
her
.

The.Netfr
ameworkconsist
sofanenormousli
brar
yofcodesusedbyt
hecl
i
entl
anguages
l
ikeVB.Net
.Thesel
anguagesuseobj
ect
-or
ient
edmethodol
ogy.

I
ntegr
atedDev
elopmentEnv
ironment(
IDE)ForVB.
Net

Mi
crosof
tpr
ovi
dest
hef
oll
owi
ngdev
elopmentt
ool
sforVB.
Netpr
ogr
ammi
ng:

• Vi
sual
Studi
o2010(
VS)

• Vi
sual
Basi
c2010Expr
ess(
VBE)

I
I
VB.
NET

• Vi
sual
WebDev
eloper
Thel asttwoaref r
ee.Usingtheset ool
s,youcanwr i
teallkindsofVB. Netpr ogramsfr
om
simplecommand- l
i
neapplicat
ionstomor ecomplexappl i
cat
ions.VisualBasicExpressand
VisualWebDev el
operExpressediti
onaretri
mmeddownv er
sionsofVi sualStudioandhas
thesamel ookandfeel
.Theyr etai
nmostf eat
uresofVisualStudio.Inthi
st ut
orial
,wehave
usedVi sualBasic2010Expr essandVi sualWebDev el
oper( f
ort hewebpr ogramming
chapter).

Youcandownloadi
tfrom here.I
tgetsautomati
call
yinst
all
ediny ourmachine.Pl
easenot
e
thaty
ouneedanact
iveint
ernetconnect
ionfori
nstal
li
ngtheexpressedit
ion.

VB.
NetHel
l
oWor
ldExampl
e

AVB.
Netpr
ogr
am basi
cal
l
yconsi
stsoft
hef
oll
owi
ngpar
ts:

• Namespacedecl
arat
ion

• Acl
assormodul
e

• Oneormor
epr
ocedur
es

• Var
iabl
es

• TheMai
npr
ocedur
e

• St
atement
s&Expr
essi
ons

• Comment
s
Letusl
ookatasi
mpl
ecodet
hatwoul
dpr
intt
hewor
ds"
Hel
l
oWor
ld"
:

I
mpor
tsSy
stem
Modul
eModul
e1
'
Thi
spr
ogr
am wi
l
ldi
spl
ayHel
l
oWor
ld
SubMai
n()
Consol
e.Wr
it
eLi
ne(
"Hel
l
oWor
ld"
)
Consol
e.ReadKey
()
EndSubEnd
Modul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:
I
II
VB.
NET

Hel
l
o,Wor
ld!

Letusl
ookv
ari
ouspar
tsoft
heabov
epr
ogr
am:

• The f
ir
stl i
ne oft he program Impor t
s Sy stem i
s used toincl
ude the Syst
em
namespaceinthepr ogr
am.
• Thenextli
nehasaModul edeclarati
on,themodul eModule1.VB.Netiscomplet
ely
obj
ectori
ented,soev er
yprogram mustcont ainamoduleofaclassthatcont
ainsthe
dat
aandpr oceduresthatyourpr
ogr am uses.

• ClassesorModul esgeneral
l
ywouldcontainmorethanoneprocedure.Pr
ocedur
es
containtheexecutabl
ecode,ori
notherwords,
theydef
inet
hebehavioroft
heclass.
Apr ocedurecoul
dbeanyoft hef
oll
owing:
o Funct ion

o Sub

o Oper
ator

• Thenextl
ine(
'Thi
spr
ogram)wi
llbeignor
edbyt
hecompi
l
erandi
thasbeenputt
o
addaddi
ti
onal
commentsint
heprogr
am.

• Thenextl i
nedefi
nest heMai nprocedur
e,whi
chi
st heent
rypoi
ntf
orallVB.
Net
programs.The Main procedur
e stat
eswhatthe modul
e orcl
asswil
ldo when
executed.

• TheMai npr
ocedurespeci
fiesi
tsbehaviorwit
hthestatement
Console.
Writ
eLine (
"Hell
o Wor l
d")Wr i
teLi
ne is a met he Consol
hod oft e cl
ass
def
ined inthe Syst
em namespace.Thi sst at
ementcausest hemessage" Hel
lo,
World!
"tobedispl
ayedont hescreen.

• Thelastl
ineConsol
e.ReadKey()isf
ort
heVS.NETUsers.Thi
swillprev
entt
hescreen
fr
om runningandcl
osingquicklywhenthepr
ogram i
slaunchedfrom Vi
sualSt
udio
.NET.

Compi
l
e&Execut
eVB.
NetPr
ogr
am

I
fyouar
eusi
ngVi
sual
Studi
o.NetI
DE,
taket
hef
oll
owi
ngst
eps:

• St
artVi
sual
Studi
o.
• Ont
hemenubar
,chooseFi
l
e New Pr
oject
.
• ChooseVi
sual
Basi
cfr
om t
empl
ates
• ChooseConsol
eAppl
i
cat
ion.

I
V
VB.
NET

• Speci
fyanameandl
ocat
ionf
ory
ourpr
ojectusi
ngt
heBr
owsebut
ton,andt
hen
chooset
heOKbut
ton.
• Thenewpr
ojectappear
sinSol
uti
onExpl
orer
.
• Wr
it
ecodei
ntheCodeEdi
tor
.
• Cl
i
ckt
heRunbut
tonort
heF5keyt
orunt
hepr
oject
.ACommandPr
omptwi
ndow
appear
sthatcont
ainst
hel
i
neHel
l
oWor
ld.

V
VB.
NET

Dat
aTy
pesAv
ail
abl
einVB.
Net

VB.Netprov
idesawi
der
angeofdat
aty
pes.Thef
oll
owi
ngt
abl
eshowsal
lthedat
aty
pes
avai
labl
e:

Dat
aTy
pe St
orageAl
locat
ion Val
ueRange

Dependson
Bool
ean Tr
ueorFal
se
i
mplementi
ngpl
atf
orm

By
te 1by
te 0t
hrough255(
unsi
gned)

Char 2by
tes 0t
hrough65535(
unsi
gned)

Dat
e 8by
tes 0:
00:00(mi
dnight
)onJanuar
y1, 0001t
hrough
11:
59:59PM onDecember31,9999

Deci
mal 16by
tes 0thr
ough+/ -
79,
228,162,
514,264,337,
593,543,
950,
335(+/
-
7.
9..
.E+28)withnodeci malpoint
;0thr
ough+/-
7.
9228162514264337593543950335wi t
h
28placestotherightofthedecimal

Doubl
e 8by
tes -
1. 79769313486231570E+308 t
hrough
4.94065645841246544E-324, f
or negati
ve
values

4.
94065645841246544E-
324 through
1.
79769313486231570E+308,
forposit
iveval
ues

I
nteger 4by
tes -
2,147,
483,
648t
hrough2,
147,
483,
647
(
signed)

Long 8by
tes -
9,223,372,036,
854,775,808 t
hrough
9,
223,372,036,854,
775,807(si
gned)

VI
VB.
NET

Obj
ect 4byteson32-
bit Anyty
pecanbest
oredi
nav
ari
abl
eoft
ype
pl
atf
orm Obj
ect
8byteson64-
bit
pl
atf
orm

SBy
te 1by
te -
128t
hrough127(
signed)

Shor
t 2by
tes -
32,
768t
hrough32,
767(
signed)

Si
ngl
e 4by
tes -3.
4028235E+38 t
hrough -
1.401298E-
45 f
or
negati
veval
ues;
1.
401298E-
45 thr
ough 3.
4028235E+38 f
or
posi
ti
veval
ues

St
ri
ng Dependson 0t
oappr
oxi
mat
ely2bi
l
li
onUni
codechar
act
ers
i
mplementi
ngpl
atf
orm

UI
nteger 4by
tes 0t
hrough4,
294,
967,
295(
unsi
gned)

ULong 8by
tes 0thr
ough18,446,
744,
073,
709,
551,
615
(
unsigned)

User- Dependson Each memberoft he str


uct
ure has a range
Defi
ned i
mplementi
ngpl
atf
orm determinedbyitsdatatypeandindependentof
therangesoftheothermembers

UShor
t 2by
tes 0t
hrough65,
535(
unsi
gned)

TheTy
peConv
ersi
onFunct
ionsi
nVB.
Net

VB.
Netpr
ovi
dest
hef
oll
owi
ngi
n-l
i
net
ypeconv
ersi
onf
unct
ions:

S.
N Funct
ions&Descr
ipt
ion

VI
I
VB.
NET

1
CBool
(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oBool
eandat
aty
pe.

2
CBy
te(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oBy
tedat
aty
pe.

3
CChar
(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oChardat
aty
pe.

4
CDat
e(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oDat
edat
aty
pe

5
CDbl
(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oDoubl
edat
aty
pe.

6 CDec(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oDeci
mal
dat
aty
pe.

7
CI
nt(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oInt
egerdat
aty
pe.

8
CLng(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oLongdat
aty
pe.

9
CObj
(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oObj
ectt
ype.

10
CSBy
te(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oSBy
tedat
aty
pe.

11
CShor
t(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oShor
tdat
aty
pe.

VI
II
VB.
NET

12
CSng(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oSi
ngl
edat
aty
pe.

13
CSt
r(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oSt
ri
ngdat
aty
pe.

14
CUI
nt(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oUI
ntdat
aty
pe.

15
CULng(
expr
essi
on)
Conv
ert
stheexpr
essi
ont
oULngdat
aty
pe.

16
CUShor
t(expr
essi
on)
Conv
ert
stheexpr
essi
ont
oUShor
tdat
aty
pe.

I
X
VB.
NET

Exampl
e

Thef
oll
owi
ngexampl
edemonst
rat
essomeoft
hesef
unct
ions:
Modul
eDataTy
pes
SubMai
n()
Di
m nAsI
nteger
Di
m daAsDat
e
Di
m bl
AsBool
ean=Tr
ue
n=1234567
da=Today
Consol
e.Wr
it
eLi
ne(
bl)
Consol
e.Wr
it
eLi
ne(
CSBy
te(
bl)
)
Consol
e.Wr
it
eLi
ne(
CSt
r(bl
))
Consol
e.Wr
it
eLi
ne(
CSt
r(da)
)
Consol
e.Wr
it
eLi
ne(
CChar
(CChar
(CSt
r(n)
)))
Consol
e.Wr
it
eLi
ne(
CChar
(CSt
r(da)
))
Consol
e.ReadKey
()
EndSub
EndModule

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

Tr
ue
-
1
Tr
ue
12/
4/2012
1
1

X
VB.
NET

Var
iabl
eDecl
arat
ioni
nVB.
Net

TheDim stat
ementi
susedf orvari
abl
edecl
arat
ionandst or
ageallocat
ionforoneormor e
var
iabl
es.TheDi
m st
atementisusedatmodul
e,class,
str
ucture,
procedure,
orblockl
evel
.

Di
m St
udent
IDAsI
nteger
Di
m St
udent
NameAsSt
ri
ng
Di
m Sal
aryAsDoubl
e
Di
m count
1,count
2AsI
nteger
Di
m st
atusAsBool
ean

Di
m exi
tBut
tonAsNewSy
stem.
Windows.
For
ms.
But
ton
Di
mlast
Time,
next
TimeAsDat
e

Var
iabl
eIni
ti
ali
zat
ioni
nVB.
Net

Vari
abl
esareinit
ial
ized (
assigned av al
ue)with an equalsi
gn f
oll
owed byaconst
ant
expr
essi
on.Thegeneralf
orm ofini
ti
ali
zati
onis:

v
ari
abl
e_name=v
alue;

f
orexampl
e,

Di
m pi
AsDoubl
epi
=3.
14159

Youcani
nit
ial
i
zeav
ari
abl
eatt
het
imeofdecl
arat
ionasf
oll
ows:

Di
m St
udent
IDAsI
nteger=100
Di
m St
udent
NameAsSt
ri
ng="
Bil
lSmi
th"

XI
VB.
NET

Exampl
e

Tr
ythef
oll
owi
ngexampl
ewhi
chmakesuseofv
ari
oust
ypesofv
ari
abl
es:

Modul
evar
iabl
esNdat
aypes
SubMai
n()
Di
m aAsShor
t
Di
m bAsI
nteger
Di
m cAsDoubl
e
a=10
b=20
c=a+b
Consol
e.Wr
it
eLi
ne(
"a={
0},
b={
1},
c={
2}"
,a,
b,c)
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

a=10,
b=20,
c=30

Accept
ingVal
uesf
rom User

TheConsol
eclassintheSystem namespaceprovi
desafunct
ionReadLi
nef
oraccept
ing
i
nputf
rom t
heuserandstor
eitint
oav ar
iabl
e.Forex
ampl
e,

Di
m messageAsSt
ri
ngmessage=Consol
e.ReadLi
ne

Thef
oll
owi
ngexampl
edemonst
rat
esi
t:

XI
I
VB.
NET

Modul
evar
iabl
esNdat
aypes
SubMai
n()
Di
m messageAsSt
ri
ng
Consol
e.Wr
it
e("
Ent
ermessage:
")
message=Consol
e.ReadLi
ne
Consol
e.Wr
it
eLi
ne(
)
Consol
e.Wr
it
eLi
ne(
"YourMessage:
{0}
",message)
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

Whentheabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t(assumet
he
useri
nput
sHell
oWorl
d):

Ent
ermessage:
Hel
l
oWor
ld
YourMessage:
Hel
l
oWor
ld

XI
II
Const
ant
s
VB.
NET

Theconstant
srefertof
ixedval
uesthatthepr
ogr
am maynotal
terdur
ingi
tsexecut
ion.
Thesef
ixedval
uesareal
socal
l
edlit
eral
s.

Const
ant
scanbeofanyofthebasi
cdatatypesl
i
keani nt
egerconst
ant,af
loat
ingconst
ant
,
achar
act
erconst
ant
,orast
ringl
it
eral
.Ther
earealsoenumerat
ionconst
ant
saswel l
.
Theconst
antsaretreatedjustl
i
ker
egul
arv
ari
abl
esexceptt
hatt
hei
rval
uescannotbe
modi
fi
edaftert
hei
rdefini
ti
on.

Decl
ari
ngConst
ant
s

I
nVB.Net,constant
saredeclaredusi
ngtheConstst
atement.TheConststatementisused
atmodul
e,class,st
ruct
ure,
procedur
e,orbl
ockl
evelf
oruseinplaceofl
i
ter
al v
alues.
Thesy
ntaxf
ort
heConstst
atementi
s:

Wher
e,eachconst
antnamehast
hef
oll
owi
ngsy
ntaxandpar
ts:

Constconst
ant
nameAs[
dat
aty
pe]=i
nit
ial
i
zer

• const
ant
name:speci
fi
est
henameoft
heconst
ant

• dat
aty
pe:speci
fi
est
hedat
aty
peoft
heconst
ant

• i
nit
ial
izer
:speci
fi
est
hev
alueassi
gnedt
otheconst
ant
Forexampl
e,

'
Thef
oll
owi
ngst
atement
sdecl
areconst
ant
s.
Constmaxv
alAsLong=4999
ConstmessageAsSt
ri
ng="
HELLO"
Constpi
Val
ueAsDoubl
e=3.
1415

XI
V
VB.
NET

Exampl
e

Thef
oll
owi
ngexampl
edemonst
rat
esdecl
arat
ionanduseofaconst
antv
alue:

Modul
econst
ant
sNenum
SubMai
n()
ConstPI=3.
14149
Di
mradi
us,
areaAsSi
ngl
e r
adi
us=7
ar
ea=PI*r
adi
us*r
adi
us
Consol
e.Wr
it
eLi
ne(
"Ar
ea="&St
r(ar
ea)
)
Consol
e.ReadKey
()
EndSubEnd
Modul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

Ar
ea=153.
933

XV
Oper
ator
s
V
VB
B.
.
NN
EE
TT

Anoperatorisasymbolthatt
ell
sthecompilertoper
form specif
icmathemati
calorl
ogi
cal
manipul
ations.VB.
Neti
srichi
nbuil
t-
inoper
atorsandprovi
desf ol
lowi
ngtypesofcommonly
usedoperators:

• Ar
it
hmet
icOper
ator
s

• Compar
isonOper
ator
s

• Logi
cal
/Bi
twi
seOper
ator
s

• Bi
tShi
ftOper
ator
s

• Assi
gnmentOper
ator
s

• Mi
scel
l
aneousOper
ator
s
Thi
stut
ori
alwi
l
lexpl
aint
hemostcommonl
yusedoper
ator
s.

Ar
it
hmet
icOper
ator
s

Fol
l
owingt
ableshowsal
ltheari
thmet
icoper
ator
ssuppor
tedbyVB.
Net
.Assumev
ari
abl
eA
hol
ds2andvari
abl
eBholds7,t
hen:

Oper
ator Descr
ipt
ion Exampl
e

^ Rai
sesoneoper
andt
othepowerofanot
her B^
Awi
l
lgi
ve49

+ Addst
wooper
ands A+Bwi
l
lgi
ve9

- Subt
ract
ssecondoper
andf
rom t
hef
ir
st A-Bwi
l
lgi
ve-
5

* Mul
ti
pli
esbot
hoper
ands A*Bwi
l
lgi
ve14

/ Divi
desoneoperandbyanot
herandr
etur
nsa B/Awi
l
lgi
ve3.
5
fl
oati
ngpointr
esult

\ Di
videsoneoper
andbyanot
herandr
etur
nsan B\Awi
l
lgi
ve3
i
ntegerr
esul
t

MOD ModulusOperat
orandr
emai
nderofaf
teran BMODAwi
l
lgi
ve1
i
ntegerdi
vi
sion

XVI
VB.
NET

Exampl
e

Tr
ythef
oll
owi
ngexampl
etounder
standal
lthear
it
hmet
icoper
ator
sav
ail
abl
einVB.
Net
:

Modul
eoper
ator
s
SubMai
n()
Di
m aAsI
nteger=21
Di
m bAsI
nteger=10
Di
m pAsI
nteger=2
Di
m cAsI
nteger Di
m
dAsSi
ngl
e c=a+b
Consol
e.Wr
it
eLi
ne(
"Li
ne1-Val
ueofci
s{0}
",c) c=a-b
Consol
e.Wr
it
eLi
ne(
"Li
ne2-Val
ueofci
s{0}
",c) c=a*b
Consol
e.Wr
it
eLi
ne(
"Li
ne3-Val
ueofci
s{0}
",c) d=a/b
Consol
e.Wr
it
eLi
ne(
"Li
ne4-Val
ueofdi
s{0}
",d) c=a\b
Consol
e.Wr
it
eLi
ne(
"Li
ne5-Val
ueofci
s{0}
",c) c=aModb
Consol
e.Wr
it
eLi
ne(
"Li
ne6-Val
ueofci
s{0}
",c) c=b^p
Consol
e.Wr
it
eLi
ne(
"Li
ne7-Val
ueofci
s{0}
",c)
Consol
e.ReadLi
ne(
)
EndSub
EndModul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

Li
ne1-Val
ueofci
s31
Li
ne2-Val
ueofci
s11
Li
ne3-Val
ueofci
s210
Li
ne4-Val
ueofdi
s2.
1
Li
ne5-Val
ueofci
s2
Li
ne6-Val
ueofci
s1
VB.
NET

Li
ne7-Val
ueofci
s100

Compar
isonOper
ator
s

Fol
l
owingtabl
eshowsallt
hecomparisonoper
ator
ssuppor
tedbyVB.
Net
.Assumev
ari
abl
e
Aholds10andvar
iabl
eBholds20,
then:
Oper
ator Descr
ipt
ion Exampl
e

=
Checksi
ftheval
uesoftwooper
andsar
eequal
ornot
;if
(
A=B)i
snott
rue.
yes,
thencondi
ti
onbecomestr
ue.

<> Checksift
heval
uesoft wooperandsareequalornot;(
A<>B)i
str
ue.
i
fvaluesar
enotequal
,thencondit
ionbecomestrue.

> Checksi
ftheval
ueoflef
toperandi
sgreat
ert
hanthe (
A>B)i
snott
rue.
val
ueofri
ghtoper
and;i
fyes,t
hencondi
ti
onbecomes
tr
ue.

< Checksi
fthev al
ueofl ef
toperandisl
essthanthe (
A<B)i
str
ue.
val
ueofri
ghtoperand;i
fyes,t
hencondi
ti
onbecomes
tr
ue.

>= Checksift
hevalueofleftoper
andisgreat
erthanor (
A>=B)i
snott
rue.
equaltothe value ofrightoper
and;ifyes,then
condi
ti
onbecomestrue.

<= Checksi
fthevalueofl
eftoperandi
slessthanorequal (
A<=B)i
str
ue.
tothevalueofr i
ghtoperand;ifyes,t
henconditi
on
becomestrue.

Tr
ythef
oll
owi
ngexampl
etounder
standal
lther
elat
ional
oper
ator
sav
ail
abl
einVB.
Net
:

XVI
II
VB.
NET

Modul
eoper
ator
s
SubMai
n()
Di
m aAsI
nteger=21
Di
m bAsI
nteger=10
I
f(a=b)Then
Consol
e.Wr
it
eLi
ne(
"Li
ne1-ai
sequal
tob"
)
El
se
Consol
e.Wr
it
eLi
ne(
"Li
ne1-ai
snotequal
tob"
)
EndI
f
I
f(a<b)Then
Consol
e.Wr
it
eLi
ne(
"Li
ne2-ai
slesst
hanb"
)
El
se
Consol
e.Wr
it
eLi
ne(
"Li
ne2-ai
snotl
esst
hanb"
)
EndI
f
I
f(a>b)Then
Consol
e.Wr
it
eLi
ne(
"Li
ne3-ai
sgr
eat
ert
hanb"
)
El
se
Consol
e.Wr
it
eLi
ne(
"Li
ne3-ai
snotgr
eat
ert
hanb"
)
EndI
f
'
Let
schangev
alueofaandb a=5 b=20
I
f(a<=b)Then
Consol
e.Wr
it
eLi
ne(
"Li
ne4-ai
sei
therl
esst
hanorequal
tob"
)
EndI
f
I
f(b>=a)Then
Consol
e.Wr
it
eLi
ne(
"Li
ne5-bi
sei
thergr
eat
ert
hanorequal
tob"
)
EndI
f
Consol
e.ReadLi
ne(
)
EndSub
EndModul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:
VB.
NET

Li
ne1-ai
snotequal
tob
Li
ne2-ai
snotl
esst
hanb
Li
ne3-ai
sgr
eat
ert
hanb
Li
ne4-ai
sei
therl
esst
hanorequal
tob
Li
ne5-bi
sei
thergr
eat
ert
hanorequal
tob

XX
Deci
sionMaki
ng
VB.
NET

Deci
sionmaki ngstruct
uresrequi
ret hatthepr
ogrammerspeci
fyoneormorecondi
ti
onsto
beevaluat
edort estedbytheprogram, al
ongwithastat
ementorstat
ement
stobeexecut
ed
i
fthecondi t
ionisdeterminedtobet rue,andopti
onal
ly
,ot
herstat
ementst
obeexecutedif
thecondit
ionisdetermi
nedt obefalse.

Foll
owingi
sthegeneralfor
m ofat
ypi
caldeci
sionmaki
ngst
ruct
uref
oundi
nmostoft
he
programmi
nglanguages:

VB.Netpr
ovi
dest
hefoll
owi
ngt
ypesofdeci
sionmaki
ngst
atement
s.Cl
i
ckt
hef
oll
owi
ngl
i
nks
tocheckt
hei
rdet
ail
s.

St
atement Descr
ipt
ion

I
f..
.Thenst
atement
AnIf..
.Then stat
ementconsi
stsofaboolean
expr
essionfol
lowedbyoneormorest
atement
s.

I
f.
..
Then.
..
Elsest
atement AnI f
..
.Thenstatementcanbef ol
lowedbyan
opti
onalElsestatement
,whichexecuteswhen
thebooleanexpr
essioni
sfal
se.

XXI
VB.
NET

nest
edI
fst
atement
s YoucanuseoneIforElseifstat
ementi
nsi
de
anot
herI
forEl
sei
fst
atement
(s)
.

Sel
ectCasest
atement ASel
ectCasestat
ementall
owsav ari
abl
etobe
t
est
edforequal
i
tyagai
nstali
stofv
alues.

nest
edSel
ectCasest
atement
s Youcanuseonesel ectcasestat
ementi
nsi
de
anot
hersel
ectcasest
atement
(s)
.

I
f.
..
ThenSt
atement

I
ti sthe si
mplestfor
m ofcont
rolstat
ement,frequent
lyused in decisi
on making and
changi
ngthecontr
olfl
owoft
heprogr
am execut
ion.Synt
axfori
f-
thenstatementis:

I
fcondi
ti
onThen
[
Stat
ement
(s)
]
EndI
f

Where,condi
ti
on i
saBool ean orr
elat
ionalcondi
ti
on and St
atement
(s)i
sasi
mpl
eor
compoundstat
ement.Exampl
eofanIf-
Thenstatementi
s:

I
f(a<=20)Then
c=c+1
EndI
f

I
ft hecondit
ionevaluat
est otrue,thentheblockofcodeinsi
detheIfst
atementwi
llbe
executed.I
fconditi
onevaluat
est of al
se,t
henthefi
rstsetofcodeaf
tert
heendoftheIf
statement(
aftert
heclosi
ngEndI f)will
beexecut
ed.

XXI
I
VB.
NET

Fl
owDi
agr
am

Exampl
e
Modul
edeci
sions
SubMai
n()
'
l
ocal
var
iabl
edef
ini
ti
on
Di
m aAsI
nteger=10

'
checkt
hebool
eancondi
ti
onusi
ngi
fst
atement
I
f(a<20)Then
'
ifcondi
ti
oni
str
uet
henpr
intt
hef
oll
owi
ng
Consol
e.Wr
it
eLi
ne(
"ai
slesst
han20"
)
EndI
f
Consol
e.Wr
it
eLi
ne(
"val
ueofai
s:{
0}"
,a)
Consol
e.ReadLi
ne(
)
EndSub
EndModul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

ai
slesst
han20v
alueofai
s:10

XXI
II
VB.
NET

I
f.
..
Then.
..
ElseSt
atement

AnIfst
atementcanbefoll
owedbyanopt
ionalEl
sest
atement
,whi
chexecut
eswhent
he
Bool
eanexpr
essi
onisf
alse.

Sy
ntax
Thesy
ntaxofanI
f.
..
Then.
..El
sest
atementi
nVB.
Neti
sasf
oll
ows:

I
f(
bool
ean_
expr
essi
on)
Then
'
stat
ement
(s)wi
l
lexecut
eift
heBool
eanexpr
essi
oni
str
ue
El
se
'
stat
ement
(s)wi
l
lexecut
eift
heBool
eanexpr
essi
oni
sfal
se

EndI
f

I
ftheBooleanexpressi
oneval
uat
est otrue,t
hent
hei
fbl
ockofcodewi
l
lbeexecut
ed,
ot
her
wiseelsebl
ockofcodewil
lbeexecut
ed.

Fl
owDi
agr
am

XXI
V
VB.
NET

Exampl
e
Modul
edeci
sions
SubMai
n()
'
l
ocal
var
iabl
edef
ini
ti
on'
Di
m aAsI
nteger=100
'
checkt
hebool
eancondi
ti
onusi
ngi
fst
atement
I
f(a<20)Then
'
ifcondi
ti
oni
str
uet
henpr
intt
hef
oll
owi
ng
Consol
e.Wr
it
eLi
ne(
"ai
slesst
han20"
)
El
se
'
ifcondi
ti
oni
sfal
set
henpr
intt
hef
oll
owi
ng
Consol
e.Wr
it
eLi
ne(
"ai
snotl
esst
han20"
)
EndI
f
Consol
e.Wr
it
eLi
ne(
"val
ueofai
s:{
0}"
,a)
Consol
e.ReadLi
ne(
)
EndSubEnd
Module
Whentheabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

ai
snotl
esst
han20v
alueofai
s:100

TheI
f.
..
ElseI
f.
..
ElseSt
atement

AnIfst
atementcanbefol
lowedbyanopti
onalEl
seif
..
.El
sest
atement
,whi
chi
sver
yusef
ul
tot
estvari
ouscondi
ti
onsusi
ngsi
ngleI
f.
..
ElseI
fst
atement
.
Whenusi
ngI
f.
..El
seI
f.
..El
sest
atement
s,t
her
ear
efewpoi
ntst
okeepi
nmi
nd.

• AnI
fcanhav
ezer
ooroneEl
se'
sandi
tmustcomeaf
teranEl
seI
f'
s.

• AnI
fcanhav
ezer
otomanyEl
seI
f'
sandt
heymustcomebef
oret
heEl
se.

• OnceanEl
sei
fsucceeds,
noneoft
her
emai
ningEl
seI
f'
sorEl
se'
swi
l
lbet
est
ed.

Sy
ntax
Thesy
ntaxofani
f.
..
elsei
f.
..
elsest
atementi
nVB.
Neti
sasf
oll
ows:

I
f(
bool
ean_
expr
essi
on1)
Then
'
Execut
eswhent
hebool
eanexpr
essi
on1i
str
ueEl
seI
f(bool
ean_
expr
essi
on2)
Then
XXV
VB.
NET

'
Execut
eswhent
hebool
eanexpr
essi
on2i
str
ue
El
seI
f(bool
ean_
expr
essi
on3)
Then
'
Execut
eswhent
hebool
eanexpr
essi
on3i
str
ue
El
se
'
execut
eswhent
henoneoft
heabov
econdi
ti
oni
str
ueEndI
f

Exampl
e
Modul
edeci
sions
SubMai
n()
'
l
ocal
var
iabl
edef
ini
ti
on'
Di
m aAsI
nteger=100
'
checkt
hebool
eancondi
ti
on'
I
f(a=10)Then
'
ifcondi
ti
oni
str
uet
henpr
intt
hef
oll
owi
ng'
Consol
e.Wr
it
eLi
ne(
"Val
ueofai
s10"
)'
El
seI
f(a=20)Then
'
i
fel
sei
fcondi
ti
oni
str
ue'
Consol
e.Wr
it
eLi
ne(
"Val
ueofai
s20"
)'
El
seI
f(a=30)Then
'
i
fel
sei
fcondi
ti
oni
str
ue
Consol
e.Wr
it
eLi
ne(
"Val
ueofai
s30"
)
El
se
'
i
fnoneoft
hecondi
ti
onsi
str
ue
Consol
e.Wr
it
eLi
ne(
"Noneoft
hev
aluesi
smat
chi
ng"
)
EndI
f
Consol
e.Wr
it
eLi
ne(
"Exactv
alueofai
s:{
0}"
,a)
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

Noneoft
hev
aluesi
smat
chi
ng

XXVI
VB.
NET

Exactv
alueofai
s:100

Nest
edI
fSt
atement
s

I
tisal
wayslegali
nVB.NettonestIf
-Then-
Elsest
atements,
whi
chmeansy
oucanuseoneI
f
orEl
seI
fst
atementinsi
deanotherI
fElseI
fstat
ement(
s).

Sy
ntax
Thesy
ntaxf
oranest
edI
fst
atementi
sasf
oll
ows:

I
f(bool
ean_
expr
essi
on1)
Then
'
Execut
eswhent
hebool
eanexpr
essi
on1i
str
ue
I
f(
bool
ean_
expr
essi
on2)
Then
'
Execut
eswhent
hebool
eanexpr
essi
on2i
str
ue
EndI
f
EndI
f

YoucannestEl
seI
f.
..
Elsei
nthesi
mil
arwayasy
ouhav
enest
edI
fst
atement
.

XXVI
I
VB.
NET

Exampl
e
Modul
edeci
sions
SubMai
n()
'
l
ocal
var
iabl
edef
ini
ti
on
Di
m aAsI
nteger=100
Di
m bAsI
nteger=200
'
checkt
hebool
eancondi
ti
on
I
f(a=100)Then
'
ifcondi
ti
oni
str
uet
hencheckt
hef
oll
owi
ng
I
f(b=200)Then
'
ifcondi
ti
oni
str
uet
henpr
intt
hef
oll
owi
ng
Consol
e.Wr
it
eLi
ne(
"Val
ueofai
s100andbi
s200"
)
EndI
f
EndI
f
Consol
e.Wr
it
eLi
ne(
"Exactv
alueofai
s:{
0}"
,a)
Consol
e.Wr
it
eLi
ne(
"Exactv
alueofbi
s:{
0}"
,b)
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

Val
ueofai
s100andbi
s200
Exactv
alueofai
s:100
Exactv
alueofbi
s:200

XXVI
II
Loops
VB.
NET

Theremaybeasi t
uati
onwhenyouneedt oexecuteabl
ockofcodesev
eral
numberofti
mes.
In general
,statement
sare executed sequent
ial
l
y:The f
ir
ststat
ementinaf unct
ion i
s
executedfi
rst
,foll
owedbythesecond,andsoon.

Programminglanguagespr
ovi
dev
ari
ouscont
rolst
ruct
urest
hatal
l
owf
ormor
ecompl
i
cat
ed
executi
onpaths.
Aloopstat
ementall
owsust oexecut
eastat
ementorgroupofstat
ementsmulti
plet
imes
and f
oll
owing i
sthe gener
alform ofa l
oop st
atementin mostofthe pr
ogramming
l
anguages:

VB.Netpr
ovidesfol
lowingtypesofl
oopst
ohandl
eloopi
ngr
equi
rement
s.Cl
i
ckt
hef
oll
owi
ng
l
inkstocheckthei
rdetail
s.

LoopTy
pe Descr
ipt
ion

DoLoop
Itr
epeatst
heenclosedblockofstatement
swhileaBool ean
condi
ti
onisTr
ueorunt i
lthecondi
ti
onbecomesTr ue.I
tcould
beter
minat
edatanytimewi t
htheExi
tDostatement.

For
..
.Next Itr
epeat
sagr oupofst
atementsaspeci
fi
ednumberofti
mes
andaloopindexcount
st henumberofl
oopit
erat
ionsasthe
l
oopexecut
es.

XXI
X
VB.
NET

ForEach.
..
Next Itrepeats a gr
oup ofstatementsforeach el
ementina
coll
ecti
on.Thisloopisusedforaccessingandmani
pul
ati
ng
all
elementsinanarrayoraVB.Netcol
lecti
on.

Whi
l
e..
.EndWhi
l
e I
texecut
esaser
iesofst
atement
sasl
ongasagi
vencondi
ti
on
i
sTrue.

Wi
th.
..EndWi
th Itisnotexactl
yaloopingconst
ruct
.Itexecut
esaser i
esof
statementsthat r
epeatedl
yrefer t
o a single obj
ect or
struct
ure.

Nest
edl
oops Youcanuseoneormor
eloopsi
nsi
deanyanot
herWhi
l
e,Foror
Doloop.

For
..
.NextLoop

I
trepeat
sagroupofst at
ementsaspeci
fi
ednumberoft
imesandal
oopi
ndexcount
sthe
numberofl
oopit
erat
ionsasthel
oopexecut
es.
Thesy
ntaxf
ort
hisl
oopconst
ructi
s:

Forcount
er[Asdat
aty
pe]=st
artToend[St
epst
ep]
[st
atement
s]
Next[count
er]

XXX
VB.
NET

Fl
owDi
agr
am

Exampl
e
Modul
eloops
SubMai
n()
Di
m aAsBy
te
'
forl
oopexecut
ion
Fora=10To20
Consol
e.Wr
it
eLi
ne(
"val
ueofa:
{0}
",a)
Next
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

XXXI
VB.
NET

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

v
alueofa:
10

v
alueofa:
11

v
alueofa:
12

v
alueofa:
13

v
alueofa:
14

v
alueofa:
15

v
alueofa:
16

v
alueofa:
17

v
alueofa:
18

v
alueofa:
19

v
alueofa:
20

I
fyouwanttouseast
epsi
zeof2,f
orexampl
e,y
ouneedt
odi
spl
ayonl
yev
ennumber
s,
bet
ween10and20:

Modul
eloops
SubMai
n()
Di
m aAsBy
te
'
forl
oopexecut
ion
Fora=10To20St
ep2
Consol
e.Wr
it
eLi
ne(
"val
ueofa:
{0}
",a)
Next
Consol
e.ReadLi
ne(
)
EndSub
EndModul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

v
alueofa:
10
v
alueofa:
12
v
alueofa:
14
v
alueofa:
16

XXXI
I
VB.
NET

v
alueofa:
18
v
alueofa:
20

Whi
l
e..
.EndWhi
l
eLoop

I
texecut
esaser
iesofst
atement
sasl
ongasagi
vencondi
ti
oni
sTr
ue.
Her
e,stat
ement(s)maybeasi nglest
atementorablockofst
atements.Thecondit
ionmay
beanyexpressi
on,andt
ruei
slogicalt
rue.Thel
oopi
terat
eswhil
ethecondit
ioni
strue.

Whenthecondi
ti
onbecomesf
alse,
progr
am cont
rol
passest
othel
i
nei
mmedi
atel
yfol
l
owi
ng
t
heloop.

Fl
owDi
agr
am

Here,keypointoftheWhi l
eloopi
sthatt
heloopmightnotev
errun.Whent hecondi
ti
onis
test
edandt heresulti
sfalse,
thel
oopbodywil
lbeski
ppedandthefi
rstst
atementaft
erthe
whil
eloopwi l
lbeexecuted.

XXXI
II
VB.
NET

Exampl
e
Modul
eloops
SubMai
n()
Di
m aAsI
nteger=10
'
whi
l
eloopexecut
ion'
Whi
l
ea<20
Consol
e.Wr
it
eLi
ne(
"val
ueofa:
{0}
",a)
a=a+1
EndWhi
l
e
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

Nest
edLoops

VB.
Netall
owsusingonel
oopi
nsi
deanot
herl
oop.Fol
l
owi
ngsect
ionshowsf
ewex
ampl
est
o
i
ll
ust
rat
etheconcept
.

Sy
ntax
Thesy
ntaxf
oranest
edForl
oopst
atementi
nVB.
Neti
sasf
oll
ows:

Forcount
er1[Asdat
aty
pe1]=st
art
1Toend1[St
epst
ep1]
Forcount
er2[Asdat
aty
pe2]=st
art
2Toend2[St
epst
ep2] .
..
Next[count
er2]

Next[count
er1]

Thesy
ntaxf
oranest
edWhi
lel
oopst
atementi
nVB.
Neti
sasf
oll
ows:

Whi
l
econdi
ti
on1
Whi
l
econdi
ti
on2
.
..
EndWhi
l
e

EndWhi
l
e

XXXI
V
VB.
NET

Exampl
e
Thef
oll
owi
ngpr
ogr
am usesanest
edf
orl
oopt
ofi
ndt
hepr
imenumber
sfr
om 2t
o100:

Modul
eloops
SubMai
n()
'
local
var
iabl
edef
ini
ti
on
Di
mi,
jAsI
nteger
Fori
=2To100
Forj
=2Toi
'
iff
act
orf
ound,
notpr
ime
I
f((
iModj
)=0)Then
Exi
tFor
EndI
f
Nextj
I
f(j
>(i
\j)
)Then
Consol
e.Wr
it
eLi
ne(
"{0}i
spr
ime"
,i)
EndI
f
Nexti
Consol
e.ReadLi
ne(
)
EndSub
EndModul
e

XXXV
VB.
NET

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

2i
spr
ime
3i
spr
ime
5i
spr
ime
7i
spr
ime
11i
spr
ime
13i
spr
ime
17i
spr
ime
19i
spr
ime
23i
spr
ime
29i
spr
ime
31i
spr
ime
37i
spr
ime
41i
spr
ime
43i
spr
ime
47i
spr
ime
53i
spr
ime
59i
spr
ime
61i
spr
ime
67i
spr
ime
71i
spr
ime
73i
spr
ime
79i
spr
ime
83i
spr
ime
89i
spr
ime
97i
spr
ime

XXXVI
St
ri
ngs
VB.
NET

I
nVB. Net,
youcanusestri
ngsasarr
ayofchar
acters,
however,mor
ecommonpract
iceisto
usetheSt r
ingkeywordt
odeclar
eastri
ngvari
able.Thest
ringkeywor
disanal
iasforthe
Syst
em. St
ringcl
ass.

Cr
eat
ingaSt
ri
ngObj
ec

Youcancr
eat
est
ri
ngobj
ectusi
ngoneoft
hef
oll
owi
ngmet
hods:

• Byassi
gni
ngast
ri
ngl
i
ter
alt
oaSt
ri
ngv
ari
abl
e

• Byusi
ngaSt
ri
ngcl
assconst
ruct
or

• Byusi
ngt
hest
ri
ngconcat
enat
ionoper
ator(
+)

• Byr
etr
iev
ingapr
oper
tyorcal
l
ingamet
hodt
hatr
etur
nsast
ri
ng

• By call
i
ng a f or
mat
ti
ng met
hod t
o conv
erta v
alue orobj
ectt
oit
s st
ri
ng
repr
esentat
ion
Thef
oll
owi
ngexampl
edemonst
rat
est
his:

Modul
est
ri
ngs
SubMai
n()
Di
mfname,
lname,
ful
l
name,
greet
ingsAsSt
ri
ng
f
name="
Rowan"
l
name="
Atki
nson"
f
ull
name=f
name+""+l
name
Consol
e.Wr
it
eLi
ne(
"Ful
lName:
{0}
",f
ull
name)

'
byusi
ngst
ri
ngconst
ruct
or
Di
mlet
ter
sAsChar
()={
"H"
,"e"
,"l
","
l"
,"o"
}
gr
eet
ings=NewSt
ri
ng(
let
ter
s)
Consol
e.Wr
it
eLi
ne(
"Gr
eet
ings:
{0}
",gr
eet
ings)
'
met
hodsr
etur
ningSt
ri
ng
Di
m sar
ray
()AsSt
ri
ng={
"Hel
l
o",
"Fr
om"
,"Tut
ori
als"
,"Poi
nt"
}
Di
m messageAsSt
ri
ng=St
ri
ng.
Joi
n(""
,sar
ray
)

XXXVI
I
VB.
NET

Consol
e.Wr
it
eLi
ne(
"Message:
{0}
",message)
Consol
e.ReadLi
ne(
)
EndSubEnd
Modul
e

Whent
heabov
ecodei
scompi
l
edandexecut
ed,
itpr
oducest
hef
oll
owi
ngr
esul
t:

Ful
lName:
RowanAt
kinson
Gr
eet
ings:
Hel
l
o
Message:
Hel
l
oFr
om Tut
ori
alsPoi
nt

Pr
oper
ti
esoft
heSt
ri
ngCl
ass

TheSt
ri
ngcl
asshast
hef
oll
owi
ngt
wopr
oper
ti
es:

S.
N Pr
oper
tyName&Descr
ipt
ion

1
Char
s
Get
stheCharobj
ectataspeci
fi
edposi
ti
oni
nthecur
rentSt
ri
ngobj
ect
.

2
Lengt
h
Get
sthenumberofchar
act
ersi
nthecur
rentSt
ri
ngobj
ect
.

XXXVI
II
VB.
NET

Met
hodsoft
heSt
ri
ngCl
ass

TheSt
ri
ngclasshasnumerousmet
hodst
hathel
pyouinworki
ngwiththest
ri
ngobj
ect
s.The
fol
l
owi
ngtableprov
idessomeoft
hemostcommonlyusedmethods:

S.
N Met
hodName&Descr
ipt
ion

1
Publ
icShar
edFunct
ionCompar
e(st
rAAsSt
ri
ng,
str
BAsSt
ri
ng)AsI
nteger
Comparestwospeci
fi
edstr
ingobj
ect
sandr
etur
nsani
ntegert
hati
ndi
cat
est
hei
r
rel
ati
veposi
ti
oni
nthesor
torder
.

2
Publ
icShar
edFunct
ionCompar
e(st
rAAsSt
ri
ng,st
rBAsSt
ri
ng,i
gnor
eCaseAs
Bool
ean)AsI
nteger
Comparest wospecif
iedstri
ngobj
ectsandr
etur
nsanintegerthatindi
cat
esthei
r
rel
ati
ve posit
ion i
nt he sor
torder
.However,iti
gnores case ifthe Bool
ean
paramet
eristrue.

3
Publ
icShar
edFunct
ionConcat(
str
0AsSt
ri
ng,
str
1AsSt
ri
ng)AsSt
ri
ng
Concat
enat
est
wost
ri
ngobj
ect
s.

4
Publ
icShar
edFunct
ionConcat(
str
0AsSt
ri
ng,
str
1AsSt
ri
ng,
str
2
AsSt
ri
ng)AsSt
ri
ng
Concat
enat
est
hreest
ri
ngobj
ect
s.

5
Publ
icShar
edFunct
ionConcat(
str
0AsSt
ri
ng,
str
1AsSt
ri
ng,
str
2
AsStr
ing,st
r3AsSt
ri
ng)AsSt
ri
ngConcat
enat
esf
our
st
ri
ngobject
s.

6
Publ
icFunct
ionCont
ains(
val
ueAsSt
ri
ng)AsBool
ean
Ret
urnsav
aluei
ndi
cat
ingwhet
hert
hespeci
fi
edst
ri
ngobj
ectoccur
swi
thi
nthi
s
st
ri
ng.

XXXI
X
VB.
NET

7
Publ
icShar
edFunct
ionCopy(
strAsSt
ri
ng)AsSt
ri
ng
Cr
eat
esanewSt
ri
ngobj
ectwi
tht
hesamev
alueast
hespeci
fi
edst
ri
ng.

8 pPubl
icSubCopy
To(
sour
ceI
ndexAsI
nteger
,dest
inat
ionAs
Char
(),
dest
inat
ionI
ndexAsI
nteger
,countAsI
nteger
)

Copi
esaspeci
fi
ednumberofchar
actersfr
om aspeci
fiedposi
ti
onoft
hest
ri
ng
obj
ectt
oaspeci
fi
edposi
ti
oni
nanarrayofUni
codechar
acter
s.

9
Publ
icFunct
ionEndsWi
th(
val
ueAsSt
ri
ng)AsBool
ean
Det
ermi
neswhet
hert
heendoft
hest
ri
ngobj
ectmat
chest
hespeci
fi
edst
ri
ng.

10
Publ
icFunct
ionEqual
s(v
alueAsSt
ri
ng)AsBool
ean
Det
ermi
neswhet
hert
hecur
rentst
ri
ngobj
ectandt
hespeci
fi
edst
ri
ngobj
ecthav
e
t
hesameval
ue.

11
Publ
icShar
edFunct
ionEqual
s(aAsSt
ri
ng,
bAsSt
ri
ng)AsBool
ean
Det
ermi
neswhet
hert
wospeci
fi
edst
ri
ngobj
ect
shav
ethesamev
alue.

12
Publ
icShar
edFunct
ionFor
mat(
for
matAsSt
ri
ng,
arg0AsObj
ect
)AsSt
ri
ng
Replaces one ormor efor
matitems i
n a speci
fi
ed st
ri
ng wi
tht
he st
ri
ng
repr
esentati
onofaspeci
fi
edobj
ect
.

13
Publ
icFunct
ionI
ndexOf(
val
ueAsChar
)AsI
nteger
Returnsthezer
o-basedi
ndexoft
hef
ir
stoccur
renceoft
hespeci
fi
edUni
code
charact
erint
hecurr
entst
ri
ng.

14
Publ
icFunct
ionI
ndexOf(
val
ueAsSt
ri
ng)AsI
nteger
Ret
urnst
hezer
o-basedi
ndexoft
hef
ir
stoccur
renceoft
hespeci
fi
edst
ri
ngi
nthi
s
i
nst
ance.

XL
VB.
NET

15 Publ
icFunct
ionI
ndexOf(
val
ueAsChar
,st
art
IndexAsI
nteger
)AsI
nteger
Returnsthezero-
basedindexofthefi
rstoccurr
enceofthespeci
fi
edUni
code
charact
erint
hisst
ring,
star
ti
ngsear
chatthespeci
fi
edchar
act
erposi
ti
on.

16
Publ
icFunct
ionI
ndexOf(
val
ueAsSt
ri
ng,
star
tI
ndexAsI
nteger
)AsI
nteger
Ret
urnst
hezero-
basedindexofthefi
rstoccurr
enceofthespeci
fi
edst
ri
ngi
nthi
s
i
nst
ance,
star
ti
ngsearchatthespeci
fi
edcharact
erposi
ti
on.

17
Publ
icFunct
ionI
ndexOf
Any(
any
OfAsChar
())AsI
nteger
Returnsthe zer
o-based i
ndexofthe f
ir
stoccurr
ence i
nthi
sinst
ance ofany
charact
erinaspecif
iedarr
ayofUni
codechar
act
ers.

18

Publ
icFunct
ionI
ndexOf
Any(
any
OfAsChar
(),
star
tI
ndexAsI
nteger
)AsI
nteger
Returnsthezero-based indexofthefi
rstoccur
renceinthi
si nst
anceofany
characteri
n a specif
ied arrayofUni
code char
acter
s,st
art
ing sear
ch att
he
specifi
edchar
acterposit
ion.

19
Publ
icFunct
ionI
nser
t(st
art
IndexAsI
nteger
,val
ueAsSt
ri
ng)AsSt
ri
ng
Retur
nsanewst r
inginwhichaspeci
fi
edst
ri
ngi
sinser
tedataspeci
fi
edi
ndex
posit
ioni
nthecurrentst
ri
ngobj
ect.

20
Publ
icShar
edFunct
ionI
sNul
lOr
Empt
y(v
alueAsSt
ri
ng)AsBool
ean
I
ndi
cat
eswhet
hert
hespeci
fi
edst
ri
ngi
snul
loranEmpt
yst
ri
ng.

XLI
VB.
NET

21
Publ
icShar
edFunct
ionJoi
n(separ
atorAsSt
ri
ng,Par
amAr
rayv
alueAsSt
ri
ng(
))
AsSt
ri
ng
Concat
enat
esal
ltheelement
sofast
ri
ngar
ray
,usi
ngt
hespeci
fi
edsepar
ator
bet
weeneachel
ement
.

22
Publ
icShar
edFunct
ionJoi
n(separ
atorAsSt
ri
ng,v
alueAsSt
ri
ng(
),st
art
IndexAs
I
nteger
,countAsI
nteger
)AsSt
ri
ng
Concatenat
es the speci
fi
ed el
ement
s ofa st
ri
ng ar
ray
,usi
ng t
he speci
fi
ed
separ
atorbetweeneachelement
.

23
Publ
icFunct
ionLast
IndexOf(
val
ueAsChar
)AsI
nteger
Ret
urnsthezer
o-basedindexposit
ionoft helastoccur
renceoft
hespeci
fi
ed
Uni
codechar
act
erwithi
nthecur
rentstr
ingobject
.

24
Publ
icFunct
ionLast
IndexOf(
val
ueAsSt
ri
ng)AsI
nteger
Ret
urnsthezero-basedi
ndexposi
ti
onoft
hel
astoccur
renceofaspeci
fi
edst
ri
ng
wit
hint
hecurrentstri
ngobj
ect
.

25
Publ
icFunct
ionRemov
e(st
art
IndexAsI
nteger
)AsSt
ri
ng
Removesallthecharactersinthecurr
entinst
ance,beginni
ng ataspeci
fi
ed
posi
ti
onandconti
nui
ngt hrought
hel
astposi
ti
on,andret
urnsthest
ring.

26
Publ
icFunct
ionRemov
e(st
art
IndexAsI
nteger
,countAsI
nteger
)AsSt
ri
ng
Removesthespeci
fi
ednumberofchar
act
ersi
nthecur
rentst
ri
ngbegi
nni
ngata
speci
fi
edposi
ti
onandret
urnst
hest
ri
ng.

27

Publ
icFunct
ionRepl
ace(
oldCharAsChar
,newCharAsChar
)AsSt
ri
ng
Repl
acesal
loccur
rencesofaspecif
iedUnicodecharacteri
nthecurrentst
ri
ng
obj
ectwi
tht
hespecif
iedUni
codechar
acterandret
urnsthenewstr
ing.

XLI
I
VB.
NET

28
Publ
icFunct
ionRepl
ace(
oldVal
ueAsSt
ri
ng,
newVal
ueAsSt
ri
ng)AsSt
ri
ng
Replacesal
loccur
rencesofaspeci
fi
edstri
ngi
nthecur
rentst
ri
ngobj
ectwi
tht
he
specif
iedst
ri
ngandretur
nsthenewstr
ing.

29
Publ
icFunct
ionSpl
i
t(Par
amAr
raysepar
atorAsChar
())AsSt
ri
ng(
)
Ret
urnsastri
ngarr
aythatcont
ainsthesubst
ri
ngsinthecur
rentst
ri
ngobj
ect
,
del
i
mi t
edbyel
ement
sofaspecif
iedUni
codechar
act
erar
ray.

30

Publ
icFunct
ionSpl
i
t(separ
atorAsChar
(),
countAsI
nteger
)AsSt
ri
ng(
)
Retur
nsastr
ingarraythatcont
ainst
hesubstri
ngsinthecurr
entst
ri
ngobj
ect
,
del
imit
edbyelementsofaspecif
iedUni
codecharact
erar
ray
.Theintpar
amet
er
speci
fi
est
hemaximum numberofsubstr
ingst
oretur
n.

31
Publ
icFunct
ionSt
art
sWi
th(
val
ueAsSt
ri
ng)AsBool
ean
Deter
mineswhet
hert
hebegi
nni
ngoft
hisst
ri
ngi
nst
ancemat
chest
hespeci
fi
ed
st
ri
ng.

32
Publ
icFunct
ionToChar
Arr
ayAsChar
()
Ret
urnsaUni
codechar
act
erar
raywi
thal
lthechar
act
ersi
nthecur
rentst
ri
ng
obj
ect.

33

Publ
icFunct
ionToChar
Arr
ay(
star
tI
ndexAsI
nteger
,lengt
hAsI
nteger
)AsChar
()
Ret
urnsaUni codechar
acterarraywithallt
hechar
acter
sinthecur
rentst
ri
ng
obj
ect,
star
ti
ngf r
om t
hespecif
iedindexanduptot
hespeci
fi
edl
engt
h.

34
Publ
icFunct
ionToLowerAsSt
ri
ng
Ret
urnsacopyoft
hisst
ri
ngconv
ert
edt
olower
case.

XLI
II
VB.
NET

35
Publ
icFunct
ionToUpperAsSt
ri
ng
Ret
urnsacopyoft
hisst
ri
ngconv
ert
edt
oupper
case.

36
Publ
icFunct
ionTr
im AsSt
ri
ng
Removesal
ll
eadi
ngandt
rai
l
ingwhi
te-
spacechar
act
ersf
rom t
hecur
rentSt
ri
ng
obj
ect
.

XLI
V
Basi
cCont
rol
s
VB.
NET

Anobjecti
sat ypeofuserinter
faceelementyoucr
eateonaVisualBasi
cfor
m byusi
nga
tool
boxcont
rol.I
nfact
,inVi
sual Basi
c,thef
ormit
sel
fisanobj
ect
.EveryVi
sual
Basi
ccontr
ol
consi
stsoft
hreeimport
antelements:

Pr
oper
ti
eswhi
chdescr
ibet
heobj
ect
,

Met
hodscauseanobj
ectt
odosomet
hingand

Ev
ent
sar
ewhathappenswhenanobj
ectdoessomet
hing.

Cont
rol
Proper
ti
es

Al
ltheVi
sualBasi
cObj
ectscanbemov ed,
resi
zed,orcustomizedbysetti
ngt
heirpr
oper
ti
es.
Aproper
tyi
sav al
ueorchar
acter
ist
ichel
dbyaVi sualBasicobject
,suchasCapti
onorFore
Col
or.

Pr
opert
iescanbesetatdesi
gntimebyusi
ngt
hePr
oper
ti
eswi
ndoworatr
unt
imebyusi
ng
st
atementsi
nthepr
ogram code.

Obj
ect
.Pr
oper
ty=Val
ue

Wher
e,

Obj
ecti
sthenameoft
heobj
ecty
ou'
recust
omi
zi
ng.

Pr
oper
tyi
sthechar
act
eri
sti
cyouwantt
,ochange.

Valuei
sthenewpr
oper
tyset
ti
ng.
Forexampl
e,

For
m1.
Capt
ion="
Hel
l
o"

Youcansetanyoftheform pr
oper
tiesusi
ngPropert
iesWindow.Mostoftheproperti
escan
besetorreaddur
ingappli
cati
onexecuti
on.Youcanr ef
ert
oMi cr
osof
tdocument at
ionfora
complet
elistofproper
ti
esassociatedwit
hdiff
erentcontrol
sandrestr
ict
ionsappliedto
them.

Cont
rol
Met
hods

Amet hodisapr ocedur


ecreat
edasamemberofacl assandtheycauseanobj ecttodo
something.Met
hodsar eusedt
oaccessormanipul
atethechar
acter
ist
icsofanobj ectora
var
iabl
e.Therear
emai nlyt
wocategor
iesofmet
hodsyouwil
luseinyourclasses:
XLV
VB.
NET

• Ify
ouareusi
ngacontr
olsuchasoneofthosepr
ovi
dedbytheTool
box,
youcancal
l
anyofi
tspubl
icmet
hods.Therequi
rement
sofsuchamethoddependonthecl
ass
bei
ngused.

• I
fnoneoftheexi
sti
ngmet
hodscanper
for
myourdesi
redt
ask,
youcanaddamet
hod
t
oaclass.

Forexampl
e,theMessageBoxcont
rolhasamet
hodnamedShow,whi
chi
scal
l
edi
nthe
codesni
ppetbel
ow:

Publ
i
cCl
assFor
m1
Pri
vat
eSubButton1_
Cli
ck(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAs
Sy
stem.
Event
Args)
Handl
esBut
ton1.
Cli
ck
MessageBox.
Show(
"Hel
l
o,Wor
ld"
)
EndSub
EndCl
ass

Cont
rol
Event
s

Anev entisasi gnalthatinf


ormsanappl icat
iont hatsomethingimportanthasoccur r
ed.For
exampl e,whenausercl i
cksacont r
olonaf or m,theform canraiseaCl i
ckev entandcalla
proceduret hathandlestheevent.Therearev ari
oustypesofev entsassociat
edwi thaForm
l
ikeclick,doublecli
ck,cl
ose,load,r
esize,
etc.

Fol
lowi
ngi st
hedef
aul
tstr
uctur
eofaf
orm Loadeventhandl
ersubr
out
ine.Youcanseethi
s
codebydoubl ecl
i
cki
ngthecodewhichwi l
lgi
vey ouacompl et
eli
stoft heallevent
s
associ
atedwit
hFor
m cont
rol
:

Pr
ivat
eSubForm1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
es
MyBase.
Load
'
eventhandl
ercodegoesher
e
EndSub

Here,HandlesMy Base.Loadindi
catesthatForm1_ Load()subrouti
nehandlesLoadev ent.
Simil
arway ,youcancheckst ubcodef orcl
ick,doublecli
ck.Ifyouwantt oini
ti
alizesome
vari
abl
eslikepropert
ies,et
c.,t
henyouwi l
lkeepsuchcodei nsideForm1_Load()subroutine.
Here,impor t
antpointt o not
eist he name oft he eventhandl er
,which is bydef ault
Form1_Load,buty oucanchanget hisnamebasedony ournami ngconventi
ony ouusei n
yourappl
icati
onprogrammi ng.
Basi
cCont
rol
s

XLVI
VB.
NET

VB.Netprovidesahugev ari
etyofcont r
olsthathel
py outocr eateri
chuseri nt
erf
ace.
Functi
onal
it
iesofallthesecontr
olsaredef
inedint
herespect
ivecontr
olcl
asses.Thecontr
ol
cl
assesaredef i
nedintheSystem.Windows.For
msnamespace.

Thef
oll
owi
ngt
abl
eli
stssomeoft
hecommonl
yusedcont
rol
s:

S.
N. Wi
dget&Descr
ipt
ion

1 For
ms
Thecont
ainerf
oral
lthecont
rol
sthatmakeupt
heuseri
nter
face.

2 Text
Box
I
trepr
esent
saWi
ndowst
extboxcont
rol
.

3 Label
I
trepr
esent
sast
andar
dWi
ndowsl
abel
.

4 But
ton
I
trepr
esent
saWi
ndowsbut
toncont
rol
.

5 Li
stBox
I
trepr
esent
saWi
ndowscont
rol
todi
spl
ayal
i
stofi
tems.

6 ComboBox
I
trepr
esent
saWi
ndowscomboboxcont
rol
.

7
Radi
oBut
ton
I
tenablestheusert
oselectasingl
eopt
ionf
rom agr
oupofchoi
ceswhenpai
red
wi
thotherRadi
oButt
oncontrol
s.

8 CheckBox
I
trepr
esent
saWi
ndowsCheckBox
.

9 Pi
ctur
eBox
I
trepr
esent
saWi
ndowspi
ctur
eboxcont
rol
fordi
spl
ayi
ngani
mage.

10 Pr
ogr
essBar
I
trepr
esent
saWi
ndowspr
ogr
essbarcont
rol
.

11 Scr
oll
Bar
I
tImpl
ement
sthebasi
cfunct
ional
i
tyofascr
oll
barcont
rol
.

XLVI
I
VB.
NET

12
Dat
eTi
mePi
cker
Itr
epresent
saWindowscont
rolt
hatal
l
owst heusert
osel
ectadat
eandat
ime
andtodispl
ayt
hedat
eandti
mewithaspeci
fi
edfor
mat.

13
Tr
eeVi
ew
I
tdispl
ays a hi
erar
chi
calcol
l
ect
ion ofl
abel
ed i
tems,each r
epr
esent
ed bya
Tr
eeNode.

14
Li
stVi
ew
Itr
epr
esentsaWi ndowsli
stvi
ewcontr
ol,whi
chdi
spl
aysacol
l
ect
ionofi
temst
hat
canbedispl
ayedusingoneoff
ourdi
ff
erentvi
ews.

XLVI
II
VB.
NET

For
ms

Let
'sst
artwithcreati
ngaWi ndow For
msAppl
i
cati
onbyfol
l
owi
ngt hefol
l
owi
ngst
epsi
n
Micr
osof
tVisualStudi
o:Fi
le-
>NewPr oj
ect-
>Wi
ndowsFor
msAppli
cati
ons

Fi
nal
l
y,sel
ectOK,Mi cr
osof
tVisualSt
udi
o cr
eat
esy
ourpr
ojectand di
spl
aysf
oll
owi
ng
wi
ndowForm wi
thanameForm1.

Vi
sualBasi
cFormist
hecontai
nerforal
lthecontrol
sthatmakeupt heuserint
erf
ace.Ever
y
wi
ndow youseeinarunni
ngv i
sualbasi
capplicati
onisaf or
m,t husthetermsf or
m and
wi
ndow descr
ibet
hesameent i
ty.Vi
sualStudi
ocr eat
esadef aul
tformf oryouwheny ou
cr
eateaWindowsFor
msAppl i
cat
ion.

Ever
yfor
m wil
lhaveti
tl
ebaronwhicht
hefor
m'scapti
onisdispl
ayedandt
her
ewi
l
lbe
butt
onst
ocl
ose,maxi
mizeandmi
nimi
zet
hef
orm shownbel
ow:

XLI
X
VB.
NET

I
fyouclicktheicononthet opleftcorner,i
topensthecontr
olmenu,whi
chcont
ainsthe
var
iouscommandst ocontr
oltheformliketomov econt
rolf
rom onepl
acet
oanot
herplace,
t
omaxi mizeormini
mizetheform ortoclosethef
orm.

For
m Pr
oper
ti
es

Foll
owingt
ablelist
sdownv ari
ousi mport
antproper
ti
esrelat
edtoaform.Thesepr
oper
ti
es
canbesetorr eadduri
ngapplicat
ionexecuti
on.Youcanr ef
ertoMi
crosof
tdocument
ati
on
foracomplet
elistofpr
oper
tiesassociat
edwithaForm contr
ol:
S.
N Pr
oper
ti
es Descr
ipt
ion

1 Accept
But
ton Thebuttonthat'
sautomat
icall
yacti
vatedwhenyoupress
Enter
,nomat terwhi
chcontrolhasthefocusatt
het i
me.
Usuall
ytheOKbut tononaf ormi ssetasAcceptBut
ton
foraform.

2 Cancel
But
ton
Thebut
tont
hat
'saut
omat
ical
l
yact
ivat
edwheny
ouhi
tthe
Esckey
.

L
VB.
NET

Usual
ly
,the Cancel but
ton on a f
orm i
s set as
Cancel
But
tonf
orafor
m.

3 Aut
oScal
e ThisBool eanpr opertydetermineswhetherthecontrol
s
youpl aceont hef orm ar
eaut omat
ical
l
yscal edtothe
heightoft he currentfont.The defaultvalue ofthi
s
propertyisTr ue.Thi si
sapr opert
yoft hefor m,buti
t
affect
st hecontrolsonthef or
m.

4 Aut
oScr
oll Thi
sBooleanpropert
yindi
cat
eswhet herscrollbar
swil
l
beaut
omat i
cal
l
yat t
achedtot
heformi fiti
sr esi
zedtoa
poi
ntt
hatnotalli
tscont
rol
sarev
isi
ble.

5 Aut
oScr
oll
MinSi
ze Thi
sproper
tylet
sy ouspeci
fyt
hemi ni
mum si
zeoft
he
for
m,bef
orethescr
oll
barsar
eatt
ached.

6 Aut
oScr
oll
Posi
ti
on TheAutoScr
oll
Posi
ti
oni
sthenumberofpi
xel
sbywhich
the t
wo scr
ollbar
s wer
e di
spl
aced f
rom t
hei
rini
tial
l
ocati
ons.

7 BackCol
or Set
sthef
orm backgr
oundcol
or.

8 Bor
der
Sty
le
The Bor
derStyl
e proper
ty deter
mines t
he st
yle oft
he
for
m'sborderandtheappearanceofthef
orm:

• None:Bor
der
lesswi
ndowt
hatcan'
tber
esi
zed.
• Si
zabl
e:Thi
sisdef
aul
tval
ueandwi
l
lbeusedf
or
r
esi
zabl
ewi
ndowt
hat
'susedf
ordi
spl
ayi
ngr
egul
ar
f
orms.
• Fi
xed3D:
Windowwi
thav
isi
blebor
der
,"r
aised"
r
elat
ivet
othemai
nar
ea.I
nthi
scase,
windows
can'
tber
esi
zed.
• Fi
xedDi
alog:
Afi
xedwi
ndow,
usedt
ocr
eat
edi
alog
boxes.
• Fi
xedSi
ngl
e:Af
ixedwi
ndowwi
thasi
ngl
eli
ne
bor
der
.

LI
VB.
NET

• Fi
xedTool
Window:
Afi
xedwi
ndowwi
thaCl
ose
but
tononl
y.I
tlooksl
i
ket
het
ool
bardi
spl
ayedby
t
hedr
awi
ngandi
magi
ngappl
i
cat
ions.
• Si
zabl
eTool
Window:
Sameast
he
FixedToolWindowbutresizabl
e.I
naddit
ion,
its
captionfontissmal
lerthantheusual
.

9 Cont
rol
Box Bydef
aul
t,t
hisproper
tyisTrueandyoucansetitt
o
Fal
set
ohi
detheiconanddi
sablet
heCont
rol
menu.

10 Enabl
ed IfTrue,al
l
ows the for
m t or espond t
o mouse and
key
boardevent
s;i
fFal
se,
disabl
esf or
m.

11 Font Thi
spr
oper
tyspeci
fyf
ontt
ype,
sty
le,
size

12 Hel
pBut
ton Det
ermi
neswhetheraHelpbut
tonshoul
dbedi
spl
ayedi
n
t
hecapt
ionboxofthef
orm.

13 Hei
ght Thi
sist
hehei
ghtoft
heFor
minpi
xel
s.

14 Mi
nimi
zeBox Bydefaul
t,t
hisproper
tyi
sTrueandyoucanseti
ttoFal
se
tohi
detheMi ni
mizebutt
onontheti
tl
ebar.

15 Maxi
mizeBox Bydef
aul
t,t
hispr
oper
tyisTrueandyoucanseti
tto
Fal
set
ohi
detheMaxi
mizebut
tonont
heti
tl
ebar
.

16 Mi
nimumSi
ze This speci
fi
es t
he minimum hei
ghtand wi
dth oft
he
windowy oucanmini
mize.

17 Maxi
mumSi
ze This speci
fi
es t
he maxi
mum hei
ghtand wi
dth oft
he
windowy oumaximi
ze.

18 Name Thi
sist
heact
ual
nameoft
hef
orm.

LI
I
VB.
NET

19 St
art
Posi
ti
on
Thi
spropert
ydeter
minestheini
ti
alposi
ti
onoft
hef or
m
whenit
'sfi
rstdi
spl
ayed.I
twil
lhaveanyofthef
oll
owing
val
ues:

• Cent
erPar
ent
:Thef
ormi
scent
eredi
nthear
eaof
i
tspar
entf
orm.
• Cent
erScr
een:Thef
ormi
scent
eredont
he
moni
tor
.
• Manual
:Thel
ocat
ionandsi
zeoft
hef
orm wi
l
l
det
ermi
nei
tsst
art
ingposi
ti
on.
• Wi
ndowsDef
aul
tBounds:Thef
ormi
s
posi
ti
onedatt
hedef
aul
tlocat
ionandsi
ze
det
ermi
nedbyWi
ndows.
• Wi
ndowsDef
aul
tLocat
ion:Thef
ormi
sposi
ti
oned
att
heWindowsdef
aultl
ocati
onandhast
he
di
mensi
onsyou'
vesetatdesi
gnti
me.

20 Text Thet
ext
,whi
chwi
l
lappearatt
het
it
lebaroft
hef
orm.

21 Top,
Lef
t Theset
woproper
ti
essetorret
urnt
hecoor
dinat
esoft
he
for
m'st
op-
lef
tcor
neri
npixel
s.

22 TopMost Thispropert
yisaTr ue/Falsevaluethatl
etsy ouspeci
fy
whethertheform wi
llremai nontopofallotherfor
msi n
yourappli
cati
on.I
tsdefaultpropert
yisFal
se.

23 Wi
dth Thi
sist
hewi
dthoft
hef
ormi
npi
xel
.

LI
II
VB.
NET

For
m Met
hods

Thefol
lowingaresomeofthecommonlyusedmethodsoftheForm cl
ass.
Youcanref
ert
o
Micr
osoftdocumentat
ionf
oracompl
eteli
stofmet
hodsassociat
edwithfor
mscontr
ol:

S.
N. Met
hodName&Descr
ipt
ion

1 Act
ivat
e
Act
ivat
est
hef
orm andgi
vesi
tfocus.

2 Act
ivat
eMdi
Chi
ld
Act
ivat
est
heMDIchi
l
dofaf
orm.

3 AddOwnedFor
m
Addsanownedf
ormt
othi
sfor
m.

4 Br
ingToFr
ont
Br
ingst
hecont
rol
tot
hef
rontoft
hez-
order
.

5 Cent
erToPar
ent
Cent
erst
heposi
ti
onoft
hef
orm wi
thi
ntheboundsoft
hepar
entf
orm.

6 Cent
erToScr
een
Cent
erst
hef
orm ont
hecur
rentscr
een.

7 Cl
ose
Cl
osest
hef
orm.

8
Cont
ains
Ret
ri
evesav
aluei
ndi
cat
ingwhet
hert
hespeci
fi
edcont
rol
isachi
l
doft
hecont
rol
.

9 Focus
Set
sinputf
ocust
othecont
rol
.

LI
V
VB.
NET

10 Hi
de
Conceal
sthecont
rol
from t
heuser
.

11
Ref
resh
Forcesthecontr
oltoi
nval
i
dat
eit
scl
i
entar
eaandi
mmedi
atel
yredr
aw i
tsel
fand
anychil
dcontr
ols.

12 Scal
e(Si
zeF)
Scal
est
hecont
rol
andal
lchi
l
dcont
rol
sbyt
hespeci
fi
edscal
i
ngf
act
or.

13 Scal
eCont
rol
Scal
est
hel
ocat
ion,
size,
paddi
ng,
andmar
ginofacont
rol
.

14 Scal
eCor
e
Per
for
msscal
i
ngoft
hef
orm.

15 Sel
ect
Act
ivat
est
hecont
rol
.

16 SendToBack
Sendst
hecont
rol
tot
hebackoft
hez-
order
.

17 Set
Aut
oScr
oll
Mar
gin
Set
sthesi
zeoft
heaut
o-scr
oll
mar
gins.

18 Set
Deskt
opBounds
Set
stheboundsoft
hef
ormi
ndeskt
opcoor
dinat
es.

19 Set
Deskt
opLocat
ion
Set
sthel
ocat
ionoft
hef
ormi
ndeskt
opcoor
dinat
es.

20 Set
Displ
ayRect
Locat
ion
Posi
ti
onst
hedi
spl
aywi
ndowt
othespeci
fi
edv
alue.

21 Show
Di
spl
ayst
hecont
rol
tot
heuser
.

22 ShowDi
alog
Showst
hef
orm asamodal
dial
ogbox.

LV
VB.
NET

For
m Ev
ent
s

Fol
lowingtabl
eli
stsdownvar
iousi
mport
antevent
srelat
edt oafor
m.Youcanr ef
ert
o
Microsof
tdocument
ati
onf
oracompl
etel
i
stofev
entsassoci
atedwi
thf
ormscont
rol
:
S.
N Ev
ent Descr
ipt
ion

1 Act
ivat
ed Occur
swhent
hef
ormi
sact
ivat
edi
ncodeorbyt
heuser
.

2 Cl
ick Occur
swhent
hef
ormi
scl
i
cked.

3 Cl
osed Occur
sbef
oret
hef
ormi
scl
osed.

4 Cl
osi
ng Occur
swhent
hef
ormi
scl
osi
ng.

5 Doubl
eCl
ick Occur
swhent
hef
orm cont
rol
isdoubl
e-cl
i
cked.

6 Dr
agDr
op Occur
swhenadr
ag-
and-
dropoper
ati
oni
scompl
eted.

7 Ent
er Occur
swhent
hef
ormi
sent
ered.

8 Got
Focus Occur
swhent
hef
orm cont
rol
recei
vesf
ocus.

9 Hel
pBut
tonCl
icked Occur
swhent
heHel
pbut
toni
scl
i
cked.

10 Key
Down Occur
swhenakeyi
spr
essedwhi
l
ethef
orm hasf
ocus.

11 Key
Press Occur
swhenakeyi
spr
essedwhi
l
ethef
orm hasf
ocus.

LVI
VB.
NET

12 Key
Up Occur
swhenakeyi
srel
easedwhi
l
ethef
orm hasf
ocus.

13 Load Occur
sbef
oreaf
ormi
sdi
spl
ayedf
ort
hef
ir
stt
ime.

14 Lost
Focus Occur
swhent
hef
orml
osesf
ocus.

15 MouseDown Occur
swhenthemousepoi
nteri
sov
ert
hef
orm anda
mousebut
toni
spr
essed.

16 MouseEnt
er Occur
swhent
hemousepoi
nterent
erst
hef
orm.

17 MouseHov
er Occur
swhent
hemousepoi
nterr
est
sont
hef
orm.

18 MouseLeav
e Occur
swhent
hemousepoi
nterl
eav
est
hef
orm.

19 MouseMov
e Occur
swhent
hemousepoi
nteri
smov
edov
ert
hef
orm.

20 MouseUp Occur
swhenthemousepoint
eri
sov
ert
hef
orm anda
mousebut
toni
srel
eased.

21 MouseWheel Occurswhent
hemousewheelmov
eswhi
l
ethecont
rol
hasfocus.

22 Mov
e Occur
swhent
hef
ormi
smov
ed.

23 Resi
ze Occur
swhent
hecont
rol
isr
esi
zed.

24 Scr
oll Occur
swhent
heuserorcodescr
oll
sthr
ought
hecl
i
ent
ar
ea.

25 Shown Occur
swhenev
ert
hef
ormi
sfi
rstdi
spl
ayed.

LVI
I
VB.
NET

26 Vi
sibl
eChanged Occur
swhent
heVi
sibl
epr
oper
tyv
aluechanges.

Text
BoxCont
rol

Textboxcont
rolsal
lowent
eri
ngtextonaform atrunt
ime.Bydefaul
t,i
ttakesasi
ngl
eli
neof
text
,however
,youcanmakeitacceptmul
ti
pletext
sandev enaddscrol
lbarstoi
t.
Let'
screat
eat
extboxbydr
aggi
ngaTextBoxcont
rolf
rom t
heTool
boxanddr
oppi
ngi
ton
thefor
m.

ThePr
oper
ti
esoft
heText
BoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heText
Boxcont
rol
:
S.
N Pr
oper
ty Descr
ipt
ion

LVI
II
VB.
NET

1 Accept
sRet
urn Get
sorsetsav al
ueindi
cati
ngwhetherpressi
ng
ENTERinamul ti
l
ineTextBoxcont
rolcreatesa
new l
i
neoftextint hecontr
oloracti
vatesthe
def
aul
tbut
tonforthefor
m.

2 Aut
oCompl
eteCust
omSour
ce Gets or sets a cust
om
System.
Collections.Special
i
zed.Str
ingCol
l
e
ct
ion t o use when the
AutoComplet eSourcepropert
yissetto
CustomSour ce.

3 Aut
oCompl
eteMode Get
s or set
s an opt
ion t
hat cont
rols how
aut
omat
iccompl
eti
onworksf
ortheTextBox.

4 Aut
oCompl
eteSour
ce Getsorset
sav al
uespeci
fyi
ngthesourceof
compl
ete str
ings used f or automat
ic
compl
eti
on.

5 Char
act
erCasi
ng Get
s or sets whet her t
he Text
Box cont
rol
modif
ies t
he case ofcharact
ers as t
heyar
e
t
yped.

6 Font Getsorset
sthef
ontoft
het
extdi
spl
ayedbyt
he
contr
ol.

7 Font
Hei
ght Get
sorset
sthehei
ghtoft
hef
ontoft
hecont
rol
.

8 For
eCol
or Get
sorset
sthef
oregr
oundcol
oroft
hecont
rol
.

9 Li
nes Get
sorset
sthel
i
nesoft
exti
nat
extboxcont
rol
.

LI
X
VB.
NET

10 Mul
ti
li
ne Get
sorsetsaval
ueindi
cat
ingwhet
hert
hisi
sa
mul
til
i
neText
Boxcont
rol
.

11 Passwor
dChar Gets or set
st he char
act
er used t
o mask
char
acter
s of a password i
n a singl
e-l
i
ne
Text
Boxcontrol
.

12 ReadOnl
y Get
sorsetsaval
ueindi
cat
ingwhet
hert
exti
nthe
t
extboxi
sread-
onl
y.

13 Scr
oll
Bar
s Getsorsetswhichscr
ollbar
sshoul
dappeari
na
multi
l
ine Text
Box control
.This pr
oper
ty has
val
ues:

• None

• Hor
izont
al
• Ver
ti
cal

Bot
h

TabI
ndex Getsorsetst
het
abor
deroft
hecont
rolwi
thi
nit
s
14 contai
ner
.

15 Text Get
sorset
sthecur
rentt
exti
ntheText
Box
.

16 Text
Ali
gn Getsorsetshow textisal
ignedi
naText
Box
cont
rol
.Thi
sproper
tyhasval
ues:

• Lef
t
• Ri
ght
• Cent
er

Text
Lengt
h Get
sthel
engt
hoft
exti
nthecont
rol
.
17

18 Wor
dWr
ap Indi
cateswhetheramul ti
l
inetextboxcont
rol
automati
call
ywrapswor dstothebegi
nni
ngof
thenextl
inewhennecessary.

LX
VB.
NET

TheMet
hodsoft
heText
BoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heText
Boxcont
rol
:
S.
N Met
hodName&Descr
ipt
ion

1
AppendText
Appendst
extt
othecur
rentt
extofat
extbox.

2 Cl
ear
Cl
ear
sal
ltextf
rom t
het
extboxcont
rol
.

3 Copy
Copi
est
hecur
rentsel
ect
ioni
nthet
extboxt
otheCl
i
pboar
d.

4 Cut
Mov
est
hecur
rentsel
ect
ioni
nthet
extboxt
otheCl
ipboar
d.

5 Past
e

Repl
acest
hecur
rentsel
ect
ioni
nthet
extboxwi
tht
hecont
ent
soft
heCl
ipboar
d.

Past
e(St
ri
ng)
Set
sthesel
ect
edt
extt
othespeci
fi
edt
extwi
thoutcl
ear
ingt
heundobuf
fer
.

7 Reset
Text
Reset
stheTextpr
oper
tyt
oit
sdef
aul
tval
ue.

8 ToSt
ri
ng
Ret
urnsast
ri
ngt
hatr
epr
esent
stheText
BoxBasecont
rol
.

9 Undo
Undoest
hel
astedi
toper
ati
oni
nthet
extbox.

LXI
VB.
NET

Ev
ent
soft
heText
BoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heTextcont
rol
:
S.
N Ev
ent Descr
ipt
ion

1 Cl
ick Occur
swhent
hecont
rol
iscl
i
cked.

2 Doubl
eCl
ick Occur
swhent
hecont
rol
isdoubl
e-cl
i
cked.

3 Text
Ali
gnChanged Occur
swhent
heText
Ali
gnpr
oper
tyv
aluechanges.

Exampl
e

I
nthisexample,wecr
eat
ethreet
extboxesandusetheCli
ckev
entofabut
tont
odi
spl
ayt
he
ent
eredtextusi
ngamessagebox.Takethef
oll
owi
ngsteps:

• Dr
aganddr
opt
hreeLabel
cont
rol
sandt
hreeText
Boxcont
rol
sont
hef
orm.

• Changet
het
ext
sont
hel
abel
sto:
Name,
Organi
zat
ionandComment
s,r
espect
ivel
y.

• Changet henamesoft hetextboxest


ot xt
Name,t
xtOrgandtxtComment,
respect
ivel
y.
• Draganddr opabuttoncont
rolont
hef or
m.Seti
tsnametobtnMessageandit
stext
propert
yto'SendMessage'
.

• Cli
ckthebut
tont
oaddt
heCl
i
ckev
enti
nthecodewi
ndow andaddt
hef
oll
owi
ng
code.

LXI
I
VB.
NET

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspont
.com"
EndSub

Pr
ivat
eSubbt
nMessage_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esbt
nMessage.
Cli
ck
MessageBox.
Show(
"Thanky
ou"+t
xtName.
Text+"f
rom "+t
xtOr
g.Text
)
EndSub
EndCl
ass

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

Cl
i
cki
ngt
heSendMessagebut
tonwoul
dshowt
hef
oll
owi
ngmessagebox:

LXI
II
VB.
NET

Label
Cont
rol

TheLabelcontr
olrepr
esent
sastandar
dWi ndowslabel
.Iti
sgener
all
yusedt
odi
spl
aysome
i
nfor
mativetextontheGUIwhi
chisnotchangedduri
ngrunt
ime.

Let
'scr
eat
eal
abel
bydr
aggi
ngaLabel
cont
rol
from t
heTool
boxanddr
oppi
ngi
tont
hef
orm.

Pr
oper
ti
esoft
heLabel
Cont
rol

LXI
V
VB.
NET

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heLabel
cont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Aut
osi
ze Get
sorsetsav aluespeci
fyi
ng i
fthecontrolshoul
d be
aut
omat
ical
l
yresi
zedtodi
spl
ayall
itscont
ent
s.

2 Bor
der
Sty
le Get
sorset
sthebor
derst
ylef
ort
hecont
rol
.

3 Fl
atSt
yle Get
sorset
sthef
latst
yleappear
anceoft
heLabel
cont
rol

4 Font Get
sorset
sthef
ontoft
het
extdi
spl
ayedbyt
hecont
rol
.

5 Font
Hei
ght Get
sorset
sthehei
ghtoft
hef
ontoft
hecont
rol
.

6 For
eCol
or Get
sorset
sthef
oregr
oundcol
oroft
hecont
rol
.

7 Pr
efer
redHei
ght Get
sthepr
efer
redhei
ghtoft
hecont
rol
.

8 Pr
efer
redWi
dth Get
sthepr
efer
redwi
dthoft
hecont
rol
.

9 TabSt
op Get
sorsetsavaluei
ndi
cat
ingwhethert
heusercant
abt
o
t
heLabel
.Thi
sproper
tyi
snotusedbythi
scl
ass.

10 Text Get
sorset
sthet
extassoci
atedwi
tht
hiscont
rol
.

11 Text
Ali
gn Get
sorset
stheal
i
gnmentoft
exti
nthel
abel
.

Met
hodsoft
heLabel
Cont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heLabel
cont
rol
:

LXV
VB.
NET

S.
N Met
hodName&Descr
ipt
ion

1 Get
Pref
err
edSi
ze
Ret
ri
evest
hesi
zeofar
ect
angul
arar
eai
ntowhi
chacont
rol
canbef
it
ted.

2 Ref
resh

For
cest
hecontrolt
oinv
ali
dat
eit
scl
i
entar
eaandi
mmedi
atel
yredr
awi
tsel
fandany
chi
l
dcontr
ols.

3 Sel
ect
Act
ivat
est
hecont
rol
.

4 Show
Di
spl
ayst
hecont
rol
tot
heuser
.

5 ToSt
ri
ng
Ret
urnsaSt
ri
ngt
hatcont
ainst
henameoft
hecont
rol
.

Ev
ent
soft
heLabel
Cont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heLabel
cont
rol
:
S.
N Ev
ent Descr
ipt
ion

1 Aut
oSi
zeChanged Occur
swhent
hev
alueoft
heAut
oSi
zepr
oper
tychanges.

2 Cl
ick Occur
swhent
hecont
rol
iscl
i
cked.

3 Doubl
eCl
ick Occur
swhent
hecont
rol
isdoubl
e-cl
i
cked.

4 Got
Focus Occur
swhent
hecont
rol
recei
vesf
ocus.

5 Leav
e Occur
swhent
hei
nputf
ocusl
eav
est
hecont
rol
.

LXVI
VB.
NET

6 Lost
Focus Occur
swhent
hecont
rol
losesf
ocus.

7 TabI
ndexChanged Occur
swhent
heTabI
ndexpr
oper
tyv
aluechanges.

8 TabSt
opChanged Occur
swhent
heTabSt
oppr
oper
tychanges.

9 Text
Changed Occur
swhent
heTextpr
oper
tyv
aluechanges.

Refert
heMicr
osoftdocument
ati
onf
oradet
ail
edl
i
stofpr
oper
ti
es,met
hodsandev
ent
sof
theLabel
cont
rol
.

Exampl
e

Foll
owingi
sanexample,whichshowshowwecancr eatetwol abels.Letuscr eat
ethefi
rst
labelfr
om t
hedesi
gnervi
ewt abandseti t
spropert
iesf r
om thepr operti
eswi ndow.Wewi l
l
uset heCl
i
ckandtheDoubleCli
ckeventsofthelabeltomov ethef i
rstlabelandchangeits
textandcr
eatet
hesecondlabelandaddittot
hef or
m, respecti
vely
.
Taket
hef
oll
owi
ngst
eps:

1.Dr
aganddr
opaLabel
cont
rol
ont
hef
orm.

2.Sett
heTextpr
oper
tyt
opr
ovi
det
hecapt
ion"
Thi
sisaLabel
Cont
rol
".

3.Sett
heFontpr
oper
tyf
rom t
hepr
oper
ti
eswi
ndow.

4.Cl
i
ckt
hel
abel
toaddt
heCl
i
ckev
enti
nthecodewi
ndowandaddt
hef
oll
owi
ngcodes.
Publ
i
cCl
assFor
m1

Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esMy
Base.
Load
'
Creat
etwobut
tonst
ouseast
heacceptandcancel
but
tons.
'
Setwi
ndowwi
dthandhei
ght
Me.
Hei
ght=300
Me.
Widt
h=560

'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspont
.com"

LXVI
I
VB.
NET

'
Displ
ayahel
pbut
tonont
hef
orm.
Me.
Hel
pBut
ton=Tr
ue
EndSub

Pr
ivat
eSubLabel
1_Cl
i
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esLabel
1.Cl
i
ck
Label
1.Locat
ion=NewPoi
nt(
50,
50)
Label
1.Text="
Youhav
ejustmov
edt
hel
abel
"
EndSub
Pr
ivat
eSubLabel
1_Doubl
eCl
i
ck(
senderAsObj
ect
,eAsEv
ent
Args)
Handl
esLabel
1.Doubl
eCl
i
ck
Di
m Label
2AsNewLabel
Label
2.Text="
NewLabel
"
Label
2.Locat
ion=NewPoi
nt(
Label
1.Lef
t,Label
1.Hei
ght+_
Label
1.Top+25)
Me.
Cont
rol
s.Add(
Label
2)
EndSub
EndCl
ass

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

Cl
i
cki
nganddoubl
ecl
i
cki
ngt
hel
abel
woul
dpr
oducet
hef
oll
owi
ngef
fect
:

LXVI
II
VB.
NET

LXI
X
VB.
NET

But
tonCont
rol

TheBut
toncont
rolrepresent
sastandar
dWindowsbut
ton.I
tisgener
all
yusedt
ogener
atea
Cli
ckev
entbypr
ov i
dingahandlerf
ortheCl
i
ckevent
.

Let
'scr
eat
eal
abel
bydr
aggi
ngaBut
toncont
rol
from t
heTool
boxaddr
oppi
ngi
tont
hef
orm.

Pr
oper
ti
esoft
heBut
tonCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heBut
toncont
rol
:
S.
N Pr
oper
ty Descr
ipt
ion

1 Aut
oSi
zeMode Getsorsetsthemodebywhi
cht
heBut
tonaut
omat
ical
l
y
resi
zesi
tsel
f.

2 BackCol
or Get
sorset
sthebackgr
oundcol
oroft
hecont
rol
.

3 Backgr
oundI
mage Getsorset
sthebackgr
oundi
magedi
spl
ayedi
nthe
contr
ol.

LXX
VB.
NET

4 Di
alogResul
t Get
sorset saval
uet
hati sr
etur
nedtothepar
entfor
m
whenthebuttoni
scl
icked.Thi
sisusedwhil
ecreati
ng
di
alogboxes.

5 For
eCol
or Get
sorset
sthef
oregr
oundcol
oroft
hecont
rol
.

6 I
mage Getsorset
sthei
maget
hati
sdi
spl
ayedonabut
ton
contr
ol.

7 Locat
ion Getsorsetst
hecoordi
nat
esoftheupper-l
eftcornerof
the cont
rolr
elat
ivetothe upper
-l
eft corner of i
ts
cont
ainer
.

8 TabI
ndex Getsorsetst
het
abor
deroft
hecont
rol
wit
hini
ts
contai
ner
.

9 Text Get
sorset
sthet
extassoci
atedwi
tht
hiscont
rol
.

Met
hodsoft
heBut
tonCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heBut
toncont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1
Get
Pref
err
edSi
ze
Ret
ri
evest
hesi
zeofar
ect
angul
arar
eai
ntowhi
chacont
rol
canbef
it
ted.

2
Not
if
yDef
aul
t
Noti
fi
esthe Butt
on whetheri
tist
he def
aul
tbut
ton so t
hati
tcan adj
usti
ts
appear
anceaccor
dingl
y.

3
Sel
ect
Act
ivat
est
hecont
rol
.

4
ToSt
ri
ng
Retur
nsaSt
ringcont
aini
ngt
henameoft
heComponent
,ifany
.Thi
smet
hodshoul
d
notbeov
err
idden.

LXXI
VB.
NET

Ev
ent
soft
heBut
tonCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heBut
toncont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 Cl
ick Occur
swhent
hecont
rol
iscl
i
cked.

2 Doubl
eCl
ick Occur
swhent
heuserdoubl
e-cl
i
ckst
heBut
toncont
rol
.

3 Got
Focus Occur
swhent
hecont
rol
recei
vesf
ocus.

4 TabI
ndexChanged Occur
swhent
heTabI
ndexpr
oper
tyv
aluechanges.

5 Text
Changed Occur
swhent
heTextpr
oper
tyv
aluechanges.

6 Val
idat
ed Occur
swhent
hecont
rol
isf
ini
shedv
ali
dat
ing.

Consul
tMicr
osoftdocument
ati
onf
ordet
ail
edl
i
stofpr
oper
ti
es,met
hodsandev
ent
soft
he
Butt
oncontr
ol.

Exampl
e

I
nthefol
l
owingexample,wecr
eatet
hreebut
tons.I
nthi
sexampl
e,l
etus:
• Setcapt
ionsf
orthebut
tons

• Setsomei
magef
ort
hebut
ton

• Handl
ethecl
i
ckev
ent
sofeachbut
tonsTakef
oll
owi
ngst
eps:

• Dr
aganddr
opaLabel
cont
rol
ont
hef
orm.

• Sett
heTextpr
oper
tyt
opr
ovi
det
hecapt
ion"
Tut
ori
alsPoi
nt"
.

• Dr
aganddr
opt
hreebut
tonsont
hef
orm.

• Usi
ngthepr
oper
ti
eswindow,changet
heNamepr
oper
ti
esoft
hebut
tonst
obt
nMot
o,
bt
nLogoandbt
nExi
trespect
ivel
y.
LXXI
I
VB.
NET

• Usi
ngthepr
opert
ieswindow,changetheTextpr
oper
ti
esoft
hebut
tonst
oShow
Moto,
ShowLogoandExitr
espect
ivel
y.

• DragandDropanotherbut
ton,usi
ngt
hepr
oper
ti
eswi
ndow,seti
tsI
magepr
oper
ty
andnameitbt
nImage.
Att
hisst
age,
thef
orml
ooksl
i
ke:

Cl
i
ckt
hef
orm andaddf
oll
owi
ngcodei
nthecodeedi
tor
:

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load

LXXI
II
VB.
NET

'
Sett
hecapt
ionbart
extoft
hef
orm. Me.
Text=
"
tut
ori
alspont
.com" bt
nImage.
Visi
ble=Fal
se
EndSub
Pr
ivat
eSubbt
nMot
o_Cl
i
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esbt
nMot
o.Cl
i
ck
bt
nImage.
Visi
ble=Fal
se
Label
1.Text="
Simpl
eEasyLear
ning"
EndSub
Pr
ivat
eSubbt
nExi
t_Cl
i
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esbt
nExi
t.
Cli
ck
Appl
i
cat
ion.
Exi
t(
)
EndSub
Pr
ivat
eSubbt
nLogo_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esbt
nLogo.
Cli
ck
Label
1.Vi
sibl
e=Fal
se bt
nImage.
Visi
ble=Tr
ue
EndSub
EndCl
ass

Cl
i
cki
ngt
hef
ir
stbut
ton,
displ
ays:

Cl
i
cki
ngt
hesecondbut
tondi
spl
ays:

LXXI
V
VB.
NET

Cl
i
cki
ngt
het
hir
dbut
ton,
exi
tst
heappl
i
cat
ion.

Li
stBoxCont
rol

TheLi st
Boxr epr
esentsaWi ndowscontroltodispl
ayal
i
stofit
emstoauser
.Ausercan
selectanit
em f r
om thel
ist
.Itallowstheprogr
ammertoaddi
temsatdesi
gnt
imebyusi
ng
thepropert
ieswindoworatther unti
me.
Let
'scr
eat
eal
i
stboxbydr
aggi
ngaLi
stBoxcont
rolf
rom t
heTool
boxanddr
oppi
ngi
tont
he
for
m.

LXXV
VB.
NET

Youcanpopul at
ethelistboxi t
emsei therf
rom theproper
ti
eswi ndoworatr unti
me.Toadd
i
temst oaLi stBox,selecttheListBoxcont r
olandgett ot hepr oper
ti
eswi ndow,forthe
proper
tiesoft
hiscontrol.Cli
cktheell
ipses(.
..
)buttonnexttotheItemsproperty
.Thisopens
theStr
ingColl
ecti
onEdi tordi
alogbox,wherey oucanenterthevaluesoneatal i
ne.

Pr
oper
ti
esoft
heLi
stBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heLi
stBoxcont
rol
:
S.
N Pr
oper
ty Descr
ipt
ion

1 Al
lowSel
ect
ion Getsav al
ueindi
cat
ing whet
hert
heLi
stBoxcur
rent
ly
enabl
essel
ect
ionofl
i
stit
ems.

2 Bor
der
Sty
le Get
sorset
sthet
ypeofbor
derdr
awnar
oundt
hel
i
stbox.

3 Col
umnWi
dth Getsofset
sthewi
dthofcol
umnsi
namul
ti
col
umnl
i
st
box.

LXXVI
VB.
NET

4 Hor
izont
alExt
ent Get
sorset
sthehor
izont
alscr
oll
i
ngar
eaofal
i
stbox.

5 Hor
izont
alScr
oll
Bar Getsorsetsthev al
ueindi
cat
ingwhet
herahor
izont
al
scr
oll
bari
sdispl
ayedint
heli
stbox.

6 I
temHei
ght Get
sorset
sthehei
ghtofani
tem i
nthel
i
stbox
.

7 I
tems Get
sthei
temsoft
hel
i
stbox
.

8 Mul
ti
Col
umn Gets orset
sav alue i
ndi
cat
ing whet
hert
he l
i
stbox
support
smulti
plecolumns.

9 Scr
oll
Alway
sVi
sibl
e Getsorset
saval
ueindi
cat
ingwhet
hert
hev
ert
icalscr
oll
bari
sshownatal
lti
mes.

10 Sel
ect
edI
ndex Get
s orsetst he zer
o-based i
ndex oft
he cur
rent
ly
sel
ect
edi
tem i
nalistbox.

11 Sel
ect
edI
ndi
ces Getsacoll
ecti
onthatcontai
nst
hezero-
basedi
ndexes
ofal
lcur
rent
lysel
ectedi
temsint
hel
istbox.

12 Sel
ect
edI
tem Get
sorset
sthecur
rent
lysel
ect
edi
tem i
nthel
i
stbox.

13 Sel
ect
edI
tems Get
sacol
lect
ioncont
aini
ngt
hecur
rent
lysel
ect
edi
tems
i
nthel
i
stbox.

14 Sel
ect
edVal
ue Get
sorset
stheval
ueofthememberpr
oper
tyspeci
fi
ed
byt
heVal
ueMemberpr
opert
y.

LXXVI
I
VB.
NET

15 Sel
ect
ionMode Get
sorsetst hemethodinwhichi t
emsar
esel
ect
edi
n
t
heli
stbox.Thispr
opert
yhasvalues:

• None

• One

• Mul
ti
Simpl
e
• Mul
ti
Ext
ended

16 Sor
ted Getsorsetsaval
ueindicat
ingwhet
hert
hei
temsi
nthe
l
istboxar
esort
edalphabeti
cal
ly
.

17 Text Get
sorsearchesfort
het
extoft
hecur
rent
lysel
ect
ed
i
tem i
nthel
i
stbox.

18 TopI
ndex Get
sorset
sthei
ndexoft
hef
ir
stv
isi
blei
tem ofal
i
st
box
.

Met
hodsoft
heLi
stBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heLi
stBoxcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1
Begi
nUpdat
e
Prev
ent
sthecont
rolf
rom dr
awi
ngunti
ltheEndUpdat
emet
hodi
scal
l
ed,
whi
l
e
i
temsareaddedt
otheList
Boxoneatatime.

2 Cl
ear
Sel
ect
ed
Unsel
ect
sal
li
temsi
ntheLi
stBox
.

3
EndUpdat
e
Resumesdr
awi
ngofal
i
stboxaf
teri
twast
urnedof
fbyt
heBegi
nUpdat
emet
hod.

4
Fi
ndSt
ri
ng
Fi
ndsthefi
rsti
tem i
ntheLi
stBoxt
hatst
art
swi
tht
hest
ri
ng speci
fi
ed asan
ar
gument
.

LXXVI
II
VB.
NET

5
Fi
ndSt
ri
ngExact
Fi
ndst
hef
ir
sti
tem i
ntheLi
stBoxt
hatexact
lymat
chest
hespeci
fi
edst
ri
ng.

6 Get
Sel
ect
ed
Ret
urnsav
aluei
ndi
cat
ingwhet
hert
hespeci
fi
edi
tem i
ssel
ect
ed.

7 Set
Sel
ect
ed
Sel
ect
sorcl
ear
sthesel
ect
ionf
ort
hespeci
fi
edi
tem i
naLi
stBox
.

8 OnSel
ect
edI
ndexChanged
Rai
sest
heSel
ect
edI
ndexChangedev
ent
.

8 OnSel
ect
edVal
ueChanged
Rai
sest
heSel
ect
edVal
ueChangedev
ent
.

Ev
ent
soft
heLi
stBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heLi
stBoxcont
rol
:
S.
N Ev
ent Descr
ipt
ion

1 Cl
i
ck Occur
swhenal
i
stboxi
ssel
ect
ed.

2 Sel
ect
edI
ndexChanged Occurswhent
heSel
ect
edI
ndexpr
oper
tyofal
i
stboxi
s
changed.

Consul
tMicr
osoftdocument
ati
onf
ordet
ail
edl
i
stofpr
oper
ti
es,met
hods,andev
ent
soft
he
Li
stBoxcont
rol
.

Exampl
e1

I
nthef
oll
owi
ngexampl
e,l
etusaddal
i
stboxatdesi
gnt
imeandaddi
temsoni
tatr
unt
ime.
Taket
hef
oll
owi
ngst
eps:

Dr
aganddr
opt
wol
abel
s,abut
tonandaLi
stBoxcont
rol
ont
hef
orm.

SettheTextproper
tyofthefi
rstlabelt
opr
ovi
det
hecapt
ion"
Choosey
ourf
avour
it
e
dest
inat
ionf
orhi
gherst
udi
es".

Sett
heTextpropert
yofthesecondl
abelt
oprovidethecapt
ion"Desti
nati
on".Thet
exton
t
hisl
abelwil
lchangeatr
untimewhentheuserselect
sanitem ontheli
st.

LXXI
X
VB.
NET

Cl
i
ckt
hel
i
stboxandt
hebut
toncont
rol
stoaddt
hef
oll
owi
ngcodesi
nthecodeedi
tor
.

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspont
.com"
Li
stBox
1.I
tems.
Add(
"Canada"
)
Li
stBox
1.I
tems.
Add(
"USA"
)
Li
stBox
1.I
tems.
Add(
"UK"
)
Li
stBox
1.I
tems.
Add(
"Japan"
)
Li
stBox
1.I
tems.
Add(
"Russi
a")
Li
stBox
1.I
tems.
Add(
"Chi
na"
) Li
stBox
1.I
tems.
Add(
"I
ndi
a")
EndSub

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
MsgBox(
"Youhav
esel
ect
ed"+Li
stBox
1.Sel
ect
edI
tem.
ToSt
ri
ng(
))

EndSub
Pr
ivat
eSubLi
stBox1_
Sel
ect
edI
ndexChanged(
senderAsObj
ect
,eAsEv
ent
Args)

Handl
esLi
stBox1.
Sel
ect
edI
ndexChanged
Label
2.Text=Li
stBox1.
Sel
ect
edI
tem.
ToSt
ri
ng(
)
EndSubEndCl
ass

Whentheabovecodeisexecut
edandrunusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowthef
oll
owi
ngwindow:

LXXX
VB.
NET

Whent
heuserchoosesadest
inat
ion,
thet
exti
nthesecondl
abel
changes:

Cl
i
cki
ngt
heSel
ectbut
tondi
spl
aysamessageboxwi
tht
heuser
'schoi
ce:

Exampl
e2

LXXXI
VB.
NET

I
nt hi
sexample,wewi l
lfi
llupal
i
stboxwit
hit
ems,r
etr
iev
ethetotalnumberofi
temsi
nthe
l
istbox,
sortt
helistbox,r
emovesomeit
emsandcl
eart
heenti
reli
stbox.
Desi
gnt
heFor
m:

Addt
hef
oll
owi
ngcodei
nthecodeedi
torwi
ndow:

LXXXI
I
VB.
NET

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspont
.com"
'
creat
ingmul
ti
-col
umnandmul
ti
sel
ectl
i
stbox
Li
stBox
1.Mul
ti
Col
umn=Tr
ue Li
stBox
1.Sel
ect
ionMode=
Sel
ect
ionMode.
Mul
ti
Ext
ended
EndSub
'
popul
atest
hel
i
st
Pr
ivat
eSubBut
ton1_
Cli
ck_
1(senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton1.
Cli
ck
Li
stBox
1.I
tems.
Add(
"Saf
ety
")
Li
stBox
1.I
tems.
Add(
"Secur
it
y")
Li
stBox
1.I
tems.
Add(
"Gov
ernance"
) Li
stBox
1.I
tems.
Add(
"GoodMusi
c")
Li
stBox
1.I
tems.
Add(
"GoodMov
ies"
)
Li
stBox
1.I
tems.
Add(
"GoodBooks"
)
Li
stBox
1.I
tems.
Add(
"Educat
ion"
)
Li
stBox
1.I
tems.
Add(
"Roads"
)
Li
stBox
1.I
tems.
Add(
"Heal
th"
)

LXXXI
II
VB.
NET

Li
stBox
1.I
tems.
Add(
"Foodf
oral
l
")
Li
stBox
1.I
tems.
Add(
"Shel
terf
oral
l
")
Li
stBox
1.I
tems.
Add(
"I
ndust
ri
ali
sat
ion"
)
Li
stBox
1.I
tems.
Add(
"Peace"
)
Li
stBox
1.I
tems.
Add(
"Li
ber
ty"
)
Li
stBox
1.I
tems.
Add(
"Fr
eedom ofSpeech"
)
EndSub
'
sor
ti
ngt
hel
i
st
Pr
ivat
eSubBut
ton2_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton2.
Cli
ck
Li
stBox
1.Sor
ted=Tr
ue
EndSub
'
cl
ear
sthel
i
st
Pr
ivat
eSubBut
ton3_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton3.
Cli
ck
Li
stBox
1.I
tems.
Clear
()
EndSub
'
remov
ingt
hesel
ect
edi
tem
Pr
ivat
eSubBut
ton4_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton4.
Cli
ck
Li
stBox
1.I
tems.
Remov
e(Li
stBox
1.Sel
ect
edI
tem.
ToSt
ri
ng)
EndSub
'
count
ingt
henumerofi
tems
Pr
ivat
eSubBut
ton5_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton5.
Cli
ck
Label
1.Text=Li
stBox1.
It
ems.
Count
EndSub
'
di
spl
ayi
ngt
hesel
ect
edi
tem ont
het
hir
dlabel
Pr
ivat
eSubLi
stBox1_
Sel
ect
edI
ndexChanged(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esLi
stBox1.
Sel
ect
edI
ndexChanged
Label
3.Text=Li
stBox1.
Sel
ect
edI
tem.
ToSt
ri
ng(
)
EndSub
EndCl
ass

LXXXI
V
VB.
NET

Whentheabovecodeisexecut
edandrunusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowthef
oll
owi
ngwindow:

Fi
l
lthel
i
standcheckwor
kingsofot
herbut
tons:

ComboBoxCont
rol

The ComboBoxcont r
olis used t
o displ
aya drop-
down li
stofvari
ous i
tems.I
tisa
combinati
onofatextboxi
nwhi chtheuserent
ersanit
em andadr
op-downli
stfr
om whi
ch
theusersel
ect
sanitem.

Let
'scr
eateacomboboxbydr
aggi
ngaComboBoxcont
rolf
rom t
heTool
boxanddr
oppi
ngi
t
onthefor
m.

LXXXV
VB.
NET

Youcanpopulatethelistboxit
emsei therf
rom theproper
ti
eswi ndoworatr unti
me.Toadd
i
temst oaLi stBox,selecttheList
Boxcont rolandgot ot hepr oper
ti
eswi ndow forthe
proper
tiesoft
hiscontr
ol .Cl
i
cktheell
ipses(.
..
)buttonnexttotheItemsproperty
.Thisopens
theStr
ingColl
ecti
onEdi t
ordial
ogbox,whereyoucanent erthevaluesoneatal i
ne.

Pr
oper
ti
esoft
heComboBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heComboBoxcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Al
lowSel
ect
ion Getsaval
ueindi
cat
ingwhethert
hel
i
st
enabl
essel
ecti
onofli
sti
tems.

2 Aut
oCompl
eteCust
omSour
ce Getsorsetsacust om
System.Col
lections.Special
i
zed.St
ri
ngC
ol
lecti
ontousewhent he
AutoComplet eSourcepropert
yissetto
CustomSour ce.

LXXXVI
VB.
NET

3 Aut
oCompl
eteMode Get
sorsetsanopt
iont
hatcont
rolshow
aut
omati
ccomplet
ionwor
ksforthe
ComboBox.

4 Aut
oCompl
eteSour
ce Getsorsetsav al
uespecif
yingthesour
ceof
complet
est r
ingsusedforautomati
c
complet
ion.

5 Dat
aBi
ndi
ngs Get
sthedat
abi
ndi
ngsf
ort
hecont
rol
.

6 Dat
aManager Getst
heCurrency
Managerassoci
atedwi
th
t
hiscont
rol
.

7 Dat
aSour
ce Get
sorsetsthedat
asour
cef
ort
his
ComboBox.

8 Dr
opDownHei
ght Getsorset
stheheighti
npi
xel
soft
hedr
op-
downporti
onoftheComboBox.

9 Dr
opDownSt
yle Get
sorset
savaluespeci
fyi
ngt
hest
yleof
t
hecombobox.

10 Dr
opDownWi
dth Getsorset
sthewi
dthoft
heofthedr
op-
downporti
onofacombobox.

11 Dr
oppedDown Getsorset
saval
ueindicati
ngwhethert
he
comboboxisdi
spl
ayingitsdrop-
down
por
tion.

12 Fl
atSt
yle Get
sorsetstheappear
anceoft
he
ComboBox.

13 I
temHei
ght Getsorset
sthehei
ghtofani
tem i
nthe
combobox.

LXXXVI
I
VB.
NET

14 I
tems Get
sanobjectrepr
esenti
ngt
hecol
lect
ionof
t
heitemscontai
nedinthi
sComboBox.

15 MaxDr
opDownI
tems Getsorset
st hemaxi
mum numberofi
tems
tobedispl
ayedint
hedropdownpar
tofthe
combobox.

16 MaxLengt
h Getsorsetsthemaximum numberof
charact
ersausercanent
erintheedi
tabl
e
areaofthecombobox.

17 Sel
ect
edI
ndex Get
sorsetstheindexspeci
fyi
ngt
he
cur
rent
lysel
ect
edi t
em.

18 Sel
ect
edI
tem Get
sorsetscur
rent
lysel
ect
edi
tem i
nthe
ComboBox.

19 Sel
ect
edText Get
sorsetsthetextt
hati
ssel
ect
edi
nthe
edi
tabl
eport
ionofaComboBox.

20 Sel
ect
edVal
ue Get
sorsetsthevalueoft
hemember
pr
oper
tyspecif
iedbytheVal
ueMember
pr
oper
ty.

21 Sel
ect
ionLengt
h Getsorset
sthenumberofchar
act
ers
sel
ectedi
ntheedi
tabl
eport
ionoft
hecombo
box.

22 Sel
ect
ionSt
art Get
sorset
sthest
art
ingi
ndexoft
ext
sel
ect
edi
nthecombobox.

23 Sor
ted Getsorset
saval
ueindi
cati
ngwhethert
he
i
temsinthecomboboxaresor
ted.

LXXXVI
II
VB.
NET

24 Text Getsorset
sthet
extassoci
atedwi
tht
his
contr
ol.

Met
hodsoft
heComboBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heComboBoxcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1
Begi
nUpdat
e
Prev
ent
st hecontr
olfrom dr
awi
nguntilt
heEndUpdat
emet
hodi
scal
l
ed,whi
l
e
i
temsareaddedtothecomboboxoneatati
me.

2
EndUpdat
e
Resumesdr
awi
ngofacombobox,af
teri
twast
urnedof
fbyt
heBegi
nUpdat
e
method.

3
Fi
ndSt
ri
ng
Fi
ndst
hefi
rsti
tem i
nthecomboboxt
hatst
art
swi
tht
hest
ri
ngspeci
fi
edasan
ar
gument
.

4
Fi
ndSt
ri
ngExact
Fi
ndst
hef
ir
sti
tem i
nthecomboboxt
hatexact
lymat
chest
hespeci
fi
edst
ri
ng.

5 Sel
ect
All
Sel
ect
sal
lthet
exti
ntheedi
tabl
ear
eaoft
hecombobox.

Ev
ent
soft
heComboBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heComboBoxcont
rol
:

S.
N Ev
ent Descr
ipt
ion

LXXXI
X
VB.
NET

1 Dr
opDown Occur
swhenthedr
op-downpor
ti
onofa
comboboxi
sdispl
ayed.

2 Dr
opDownCl
osed Occur
swhenthedr
op-downporti
onofa
comboboxi
snolongervi
sibl
e.

3 Dr
opDownSt
yleChanged Occur
swhentheDropDownSty
lepr
oper
tyof
t
heComboBoxhaschanged.

4 Sel
ect
edI
ndexChanged Occur
swhent heSelect
edI
ndexproper
tyofa
ComboBoxcontr
olhaschanged.

5 Sel
ect
ionChangeCommi
tt
ed Occurswhentheselect
edit
em haschanged
andthechangeappear
sint
hecombobox .

Exampl
e

I
nthisexampl
e,l
etusfi
l
lacomboboxwi thvari
ousit
ems,gett
hesel
ect
edi
temsi
nthe
comboboxandshowt
hem i
nal
istboxandsor
ttheit
ems.

Draganddr
opacomboboxtostor
et heit
ems,alistboxtodi
spl
aythesel
ect
edit
ems,f
our
butt
oncont
rol
stoaddtot
heli
stboxwi t
hselect
edi t
ems,tof
il
lthecombobox,t
osor
tthe
i
temsandtocl
eart
hecomboboxli
st,
respect
ivel
y.
Addal
abel
cont
rol
thatwoul
ddi
spl
ayt
hesel
ect
edi
tem.

XC
VB.
NET

Addthefol
lowi
ngcodei
nthecodeedi
torwi
ndow:
Publi
cClassFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspont
.com"
EndSub
'
sendst
hesel
ect
edi
temst
othel
i
stbox
Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
I
fComboBox1.
Sel
ect
edI
ndex>-
1Then Di
m
si
ndexAsI
nteger
si
ndex=ComboBox1.
Sel
ect
edI
ndex Di
m
si
tem AsObj
ect
si
tem =ComboBox1.
Sel
ect
edI
tem
Li
stBox1.
It
ems.
Add(
sit
em)
EndI
f
EndSub
'
popul
atest
hel
i
st
Pr
ivat
eSubButt
on2_
Cli
ck(senderAsObj ect
,eAsEv
ent
Args)Handl
esBut
ton2.
Cli
ck
ComboBox1.
It
ems.
Clear
()
ComboBox1.
It
ems.
Add("
Saf et
y")
ComboBox1.
It
ems.
Add("
Secur i
ty"
)
ComboBox1.
It
ems.
Add("
Gov ernance") ComboBox1.I
tems.
Add("
GoodMusic"
)
ComboBox1.
It
ems.
Add("
GoodMov i
es")
XCI
VB.
NET

ComboBox1. I
tems. Add("GoodBooks" )
ComboBox1. I
tems. Add("Educat i
on")
ComboBox1. I
tems. Add("Roads" )
ComboBox1. I
tems. Add("Health")
ComboBox1. I
tems. Add("Foodf orall"
)
ComboBox1. I
tems. Add("Shelterforall
")
ComboBox1. I
tems. Add("Industri
ali
sati
on" )
ComboBox1. I
tems. Add("Peace" )
ComboBox1. I
tems. Add("Liberty
")
ComboBox1. I
tems. Add("Freedom ofSpeech" )
ComboBox1. Text=" Selectfrom..."
EndSub
'sorti
ngt heli
st
Pr iv
at eSubBut t
on3_Cl i
ck(senderAsObj ect,eAsEventArgs)
ComboBox1. Sorted=Tr ue
EndSub
'clearst heli
st
Pr iv
at eSubBut t
on4_Cl i
ck(senderAsObj ect,eAsEventArgs)
ComboBox1. I
tems. Clear(
)
EndSub
'displayingthesel ect
edi tem ont helabel
Pr iv
at eSubComboBox1_ SelectedIndexChanged(senderAsObject
,eAsEv
ent
Args)_
Handl esListBox1.SelectedIndexChanged
Label 1.Text=ComboBox1. SelectedIt
em. ToStr
ing(
)
EndSub
EndCl ass

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

XCI
I
VB.
NET

Cl
i
ckonv
ari
ousbut
tonst
ocheckt
heact
ionsper
for
medbyeach:

Radi
oBut
tonCont
rol

TheRadi oBut
toncont r
olisusedt oprovi
deasetofmut uall
yexclusi
veopt
ions.Theusercan
selectoneradiobuttoninagr oup.I
fyouneedtoplacemor ethanonegroupofradi
obut t
ons
inthesamef orm,y oushouldpl acethem i
ndiff
er entcontai
nercont
rol
sl i
keaGr oupBox
control.
Let'
scr eatethreeradiobuttonsbydr aggi
ngRadi oButt
oncont rol
sfr
om theToolboxand
droppingonthef or
m.

XCI
II
VB.
NET

TheCheckedpr oper
tyofther
adiobuttonisusedtosetthest
ateofar adi
obut
ton.Youcan
displ
aytext
,imageorbothonr adiobutt
oncontrol
.Youcanalsochangetheappear
anceof
theradi
obuttoncontr
olbyusi
ngt heAppearancepr
oper
ty.

Pr
oper
ti
esoft
heRadi
oBut
tonCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heRadi
oBut
toncont
rol
:
S.
N Pr
oper
ty Descr
ipt
ion

1 Appear
ance
Get
sorset
sav
aluedet
ermi
ningt
heappear
anceoft
her
adi
o
but
ton.

2 Aut
oCheck Get
sorset savaluei
ndicat
ingwhet
hertheCheckedval
ue
andtheappearanceoft hecont
rolaut
omati
call
ychange
whenthecont
roli
scli
cked.

3 CheckAl
ign Get
sorsetsthel
ocat
ionoft
hecheckboxpor
ti
onoft
he
r
adi
obut
ton.

4 Checked Getsorsetsav
aluei
ndi
cat
ingwhet
hert
hecont
rol
is
checked.

5 Text Get
sorset
sthecapt
ionf
orar
adi
obut
ton.

6 TabSt
op Getsorsetsav al
ueindi
cat
ingwhetherausercangi
ve
focust
otheRadi
oButt
oncont
rolusi
ngtheTABkey
.

Met
hodsoft
heRadi
oBut
tonCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heRadi
oBut
toncont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 Per
for
mCl
ick
Gener
atesaCl
i
ckev
entf
ort
hecont
rol
,si
mul
ati
ngacl
i
ckbyauser
.

Ev
ent
soft
heRadi
oBut
tonCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heRadi
oBut
toncont
rol
:
XCI
V
VB.
NET

S.
N Ev
ent Descr
ipt
ion

1 Appear
anceChanged
Occur
swhent heval
ueoftheAppearancepr
oper
tyof
t
heRadioBut
toncont
rol
ischanged.

2 CheckedChanged Occur
swhent heval
ueoftheCheckedpr
oper
tyoft
he
Radi
oBut
toncontr
oli
schanged.

Consul
tMicr
osof
tdocument
ati
onf
ordet
ail
edl
i
stofpr
oper
ti
es,met
hodsandev
ent
soft
he
Radi
oButt
oncont
rol
.

Exampl
e

I
nt he fol
lowing example,letus cr
eat
et wo gr
oups ofradi
o butt
ons and use t
hei
r
CheckedChangedev ent
sforchangi
ngt
heBackCol
orandFor
eColorpr
opert
yofthefor
m.

Let
'sdoubl
ecl
i
ckont
her
adi
obut
tonsandputt
hef
oll
owcodei
ntheopenedwi
ndow.

XCV
VB.
NET

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspont
.com"
EndSub

Pr
ivat
eSubRadi
oBut
ton1_
CheckedChanged(
senderAsObj
ect
,_ eAs
Ev
ent
Args)Handl
esRadi
oBut
ton1.
CheckedChanged
Me.
BackCol
or=Col
or.
Red
EndSub
Pr
ivat
eSubRadi
oBut
ton2_
CheckedChanged(
senderAsObj
ect
,_ eAs
Ev
ent
Args)Handl
esRadi
oBut
ton2.
CheckedChanged
Me.
BackCol
or=Col
or.
Green
EndSub
Pr
ivat
eSubRadi
oBut
ton3_
CheckedChanged(
senderAsObj
ect
,_ eAs
Ev
ent
Args)Handl
esRadi
oBut
ton3.
CheckedChanged
Me.
BackCol
or=Col
or.
Blue
EndSub

Priv
at eSubRadi oBut
ton4_CheckedChanged(senderAsObject
,_ eAs
EventAr gs)Handl
esRadioButton4.
CheckedChanged
Me. ForeCol
or=Color.
Black
EndSub
Priv
at eSubRadi oBut
ton5_CheckedChanged(senderAsObject
,_ eAs
EventAr gs)Handl
esRadioButton5.
CheckedChanged
Me. ForeCol
or=Color.
Whi t
e
EndSub
Priv
at eSubRadi oBut
ton6_CheckedChanged(senderAsObject
,_ eAs
EventAr gs)Handl
esRadioButton6.
CheckedChanged Me. ForeCol
or=Col
or.
Red
EndSub
EndCl ass

Whentheabovecodeisexecut
edandrunusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowthef
oll
owi
ngwindow:

XCVI
VB.
NET

CheckBoxCont
rol

TheCheckBoxcontr
olal
lowst
heusert
osett
rue/f
alseoryes/
not
ypeopt
ions.Theusercan
sel
ectordeselecti
t.Whenacheckboxi
sselectedithasthev
alueTr
ue,andwheni tis
cl
eared,
ithol
dstheval
ueFal
se.

Let
'scr
eatet
wocheckboxesbydr
aggi
ngCheckBoxcont
rol
sfr
om t
heTool
boxanddr
oppi
ng
onthefor
m.

TheCheckBoxcontrolhast hr
eestat
es,checked,uncheckedandindeterminate.Inthe
i
ndet
erminat
e st
ate,the check boxi
s grayed out
.To enablethe i
ndeterminate st
ate,
XCVII
VB.
NET

heThr
t eeSt
atepr
oper
tyoft
hecheckboxi
ssett
obeTr
ue.

Pr
oper
ti
esoft
heCheckBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heCheckBoxcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Appear
ance
Getsorsetsa v
aluedet
ermi
ning t
heappear
anceoft
he
checkbox.

2 Aut
oCheck Getsorset sav alueindi
cating whethertheChecked or
CheckedStat
ev al
ue and the appearance oft he cont
rol
aut
omat i
call
ychangewhent hecheckboxi ssel
ected.

3 CheckAl
ign Getsorsetst
hehor i
zont
alandv
ert
icalal
i
gnmentoft
he
checkmar
konthecheckbox.

4 Checked Get
sorsetsav
aluei
ndi
cat
ingwhet
hert
hecheckboxi
s
sel
ect
ed.

5 CheckSt
ate Get
sorset
sthest
ateofacheckbox
.

6 Text Get
sorset
sthecapt
ionofacheckbox
.

7 Thr
eeSt
ate Getsorsetsaval
ueindi
cati
ngwhetherornotacheckbox
shoul
dall
owthr
eecheckstat
esr
atherthant
wo.

Met
hodsoft
heCheckBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heCheckBoxcont
rol
:
S.
N Met
hodName&Descr
ipt
ion

1
OnCheckedChanged
Rai
sest
heCheckedChangedev
ent
.

XCVI
II
VB.
NET

2 OnCheckSt
ateChanged
Rai
sest
heCheckSt
ateChangedev
ent
.

3 OnCl
ick
Rai
sest
heOnCl
i
ckev
ent
.

Ev
ent
soft
heCheckBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heCheckBoxcont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 Appear
anceChanged
Occur
swhenthevalueoftheAppear
ancepr
oper
tyof
t
hecheckboxi
schanged.

2 CheckedChanged Occurswhentheval
ueoft heCheckedpr
oper
tyoft
he
CheckBoxcont
rol
ischanged.

3 CheckSt
ateChanged Occur
swhent heval
ueoft heCheckSt
atepr
oper
tyof
t
heCheckBoxcont
roli
schanged.

Consul
tMicrosoftdocument
ati
onf
ordet
ail
edl
i
stofpr
oper
ti
es,met
hodsandev
ent
soft
he
CheckBoxcontr
ol.

Exampl
e

I
nt hi
sexample,letusaddfourcheckboxesi nagr oupbox.Thecheckboxeswil
lall
owt he
userstochooset hesour
cef r
om whi chtheycamet oknow aboutt
heorgani
zat
ion.Ifthe
userchoosesthecheckboxwi thtext"ot
hers"
,thent heuseri
saskedtospeci
fyandat ext
boxi sprovi
dedt ogivei
nput.Whent heusercl i
ckst heSubmitbutt
on,he/
sheget san
appropr
iatemessage.
Thef
ormi
ndesi
gnv
iew:

XCI
X
VB.
NET

Let
'sputt
hef
oll
owi
ngcodei
nthecodeedi
torwi
ndow:

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspoi
nt.
com"
Label
1.Vi
sibl
e=Fal
se
Text
Box
1.Vi
sibl
e=Fal
se
Text
Box
1.Mul
ti
li
ne=Tr
ue
EndSub
Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton1.
Cli
ck
Di
m st
rAsSt
ri
ng st
r=""
I
fCheckBox1.
Checked=Tr
ueThen st
r&=
CheckBox1.
Text

C
VB.
NET

st
r&=""
EndI
f
I
fCheckBox2.
Checked=Tr
ueThen
st
r&=CheckBox2.
Text st
r&=""
EndI
f
I
fCheckBox3.
Checked=Tr
ueThen
st
r&=CheckBox3.
Text st
r&=""
EndI
f
I
fCheckBox4.
Checked=Tr
ueThen
st
r&=Text
Box1.
Text st
r&=""
EndI
f
I
fst
r<>Not
hingThen
MsgBox
(st
r+v
bLf+"
Thanky
ou"
)
EndI
f
EndSub
Pr
ivat
eSubCheckBox
4_CheckedChanged(
senderAsObj
ect
,_ eAs
Ev
ent
Args)Handl
esCheckBox
4.CheckedChanged
Label
1.Vi
sibl
e=Tr
ue
Text
Box
1.Vi
sibl
e=Tr
ue
EndSub
EndCl
ass

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

CI
VB.
NET

Checki
ngal
ltheboxes:

Cl
i
cki
ngt
heSubmi
tbut
ton:

CI
I
VB.
NET

Pi
ctur
eBoxCont
rol

ThePict
ureBoxcont
roli
susedf
ordi
spl
ayi
ngimagesont
hefor
m.TheImagepr
oper
tyoft
he
cont
rolal
lowsyoutosetani
magebot
hatdesi
gnti
meoratr
untime.

Let
'scr
eateapi
ctur
eboxbydr
aggi
ngaPi
ctur
eBoxcont
rolf
rom t
heTool
boxanddr
oppi
ngi
t
onthefor
m.

Pr
oper
ti
esoft
hePi
ctur
eBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
hePi
ctur
eBoxcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Al
lowDr
op Specif
ieswhet
hert
hepi
ctur
eboxaccept
sdat
athatauser
dragsonit
.

2 Er
ror
Image Getsorspeci
fiesanimagetobedi
splay
edwhenanerr
or
occur
sduringt hei
mage-l
oadi
ngpr
ocessori
ftheimage
l
oadiscancel
led.

3 I
mage Get
sorset
sthei
maget
hati
sdi
spl
ayedi
nthecont
rol
.

CI
II
VB.
NET

4 I
mageLocat
ion Get
sorsetst
hepat
hort
heURLf
ort
hei
magedi
spl
ayedi
n
t
hecont
rol
.

5 I
nit
ial
Image Get
sorset
stheimagedi
spl
ayedi
nthecont
rol
whent
he
mai
nimageisl
oaded

6 Si
zeMode
Determinesthesi
zeoft heimagetobedi spl
ayedint
he
contr
ol. This proper
ty takes it
s v al
ue f r
om the
Pict
ureBoxSi
zeModeenumerati
on,
whichhasval
ues:

• Nor
mal-t
heupperl
eftcor
neroft
hei
magei
spl
aced
atupperl
eftpar
toft
hepi
ctur
ebox
• St
rechI
mage-al
l
owsst
ret
chi
ngoft
hei
mage
• Aut
oSi
ze-al
l
owsr
esi
zi
ngt
hepi
ctur
eboxt
othesi
ze
oft
hei
mage
• Cent
erI
mage-al
l
owscent
eri
ngt
hei
magei
nthe
pi
ctur
ebox
• Zoom -al
l
owsi
ncr
easi
ngordecr
easi
ngt
hei
mage
si
zet
omai
ntai
nthesi
zer
ati
o.

TabI
ndex Get
sorset
sthet
abi
ndexv
alue.
7

8 TabSt
op Speci
fi
eswhethertheuserwillbeabl
etof
ocuson t
he
pi
ctur
eboxbyusingtheTABkey
.

9 Text Get
sorset
sthet
extf
ort
hepi
ctur
ebox
.

10 Wai
tOnLoad Speci
fi
eswhet
herornotani
magei
sloadedsy
nchr
onousl
y.

Met
hodsoft
hePi
ctur
eBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
hePi
ctur
eBoxcont
rol
:

CI
V
VB.
NET

S.
N Met
hodName&Descr
ipt
ion

1 Cancel
Asy
nc
Cancel
sanasy
nchr
onousi
magel
oad.

2 Load
Di
spl
aysani
magei
nthepi
ctur
ebox

3 LoadAsy
nc
Loadsi
mageasy
nchr
onousl
y.

4 ToSt
ri
ng
Ret
urnst
hest
ri
ngt
hatr
epr
esent
sthecur
rentpi
ctur
ebox.

Ev
ent
soft
hePi
ctur
eBoxCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
hePi
ctur
eBoxcont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 CausesVal
idat
ionChanged
Over
ri
desthe
Cont
rol
.CausesVal
i
dat
ionChangedpr
oper
ty.

2 Cl
i
ck Occur
swhent
hecont
rol
iscl
i
cked.

3 Ent
er Ov
err
idest
heCont
rol
.Ent
erpr
oper
ty.

4 Font
Changed Occurswhent
hev
alueoft
heFontpr
oper
ty
changes.

5 For
eCol
orChanged Occurswhent
hev
alueoft
heFor
eCol
orpr
oper
ty
changes.

6 Key
Down Occurswhenakeyi
spr
essedwhent
hecont
rol
hasfocus.

CV
VB.
NET

7 Key
Press Occurswhenakeyi
spr
essedwhent
hecont
rol
hasfocus.

8 Key
Up Occurswhenakeyi
srel
easedwhent
hecont
rol
hasfocus.

9 Leav
e Occur
swheni
nputf
ocusl
eav
est
hePi
ctur
eBox
.

10 LoadCompl
eted Occurs when the asynchr
onous i
mage-l
oad
operat
ion i
s completed,been cancel
ed,or
rai
sedanexcept
ion.

11 LoadPr
ogr
essChanged Occur
swhentheprogr
essofanasy nchr
onous
i
mage-l
oadi
ngoper
ati
onhaschanged.

12 Resi
ze Occur
swhent
hecont
rol
isr
esi
zed.

13 Ri
ght
ToLef
tChanged Occur
s when t he v
alue of t
he Ri
ght
ToLef
t
pr
opert
ychanges.

14 Si
zeChanged Occur
swhent
heSi
zepr
oper
tyv
aluechanges.

15 Si
zeModeChanged Occur
swhenSi
zeModechanges.

16 TabI
ndexChanged Occurswhent
hev
alueoft
heTabI
ndexpr
oper
ty
changes.

17 TabSt
opChanged Occurswhent
hev
alueoft
heTabSt
oppr
oper
ty
changes.

18 Text
Changed Occurswhent
hev
alueoft
heTextpr
oper
ty
changes.

Exampl
e

I
nthi
sexampl
e,l
etusputapi
ctur
eboxandabut
toncont
rolont
hef
orm.Wesett
hei
mage
CVI
VB.
NET

proper
tyofthepi
ctur
eboxt
ologo.
png,asweusedbefor
e.TheCl
i
ckev
entoft
hebut
ton
namedButton1i
scodedt
ost
ret
chthei
magetoaspeci
fi
edsize:

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspoi
nt.
com"
EndSub

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
Pi
ctur
eBox
1.Cl
i
ent
Size=NewSi
ze(
300,
300)
Pi
ctur
eBox
1.Si
zeMode=Pi
ctur
eBoxSi
zeMode.
Str
etchI
mage
EndSubEndCl
ass

Desi
gnVi
ew:

Whent
heappl
i
cat
ioni
sexecut
ed,
itdi
spl
ays:

CVI
I
VB.
NET

Cl
i
cki
ngont
hebut
tonr
esul
tsi
n:

CVI
II
VB.
NET

Dat
eTi
mePi
ckerCont
rol

TheDateTi
mePi ckercontr
olall
owsselect
ingadateandtimebyedi t
ingthedispl
ayedval
ues
i
nt hecontrol
.Ify oucli
ckt hearrow i
nt heDateTi
mePickercontr
ol,itdispl
aysamont h
cal
endar,l
i
keacomboboxcont rol
.Theusercanmakesel ect
ionbyclicki
ngtherequi
red
dat
e.Thenewsel ectedvalueappearsi
nthetextboxpar
tofthecontrol
.

TheMi
nDat
eandt
heMaxDat
epr
oper
ti
esal
l
owy
out
oputl
i
mit
sont
hedat
erange.

Pr
oper
ti
esoft
heDat
eTi
mePi
ckerCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heDat
eTi
mePi
ckercont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 BackCol
or
Get
sorsetsav
aluei
ndi
cati
ngt hebackgr
ound
col
oroft
heDat
eTimePi
ckercontr
ol.

2 Backgr
oundI
mage Gets orset
sthe backgr
ound i
mage f
ort
he
cont
rol.

3 Backgr
oundI
mageLay
out Get
s orset
sthe l
ayoutoft he backgr
ound
i
mageoft
heDat
eTi
mePi ckercontr
ol.

CI
X
VB.
NET

4 Cal
endar
Font Get
sorsetst
hef
ontst
yleappl
i
edt
othe
cal
endar
.

5 Cal
endar
For
eCol
or Get
sorsetst
hef
oregr
oundcol
oroft
he
cal
endar
.

6 Cal
endar
Mont
hBackgr
ound Get
s orsetst he backgr
ound col
oroft
he
cal
endarmont
h.

7 Cal
endar
Tit
leBackCol
or Get
s orset sthe backgr
ound col
oroft
he
cal
endart
it
le.

8 Cal
endar
Tit
leFor
eCol
or Get
s orset sthe f
oregr
ound col
orof t
he
cal
endart
it
le.

9 Cal
endar
Trai
li
ngFor
eCol
or Get
s orset sthe for
egr
ound col
orof t
he
cal
endart
rai
l
ingdat
es.

10 Checked Get
sorsetsav aluei
ndi
catingwhet
herthe
Val
ue pr
opert
y has been setwithav ali
d
dat
e/t
ime v
alue and t
he di
splay
ed v
alue i
s
abl
etobeupdated.

11 Cust
omFor
mat Getsorset
sthecust
om dat
e/t
imef
ormat
st
ri
ng.

12 Dr
opDownAl
ign Get
sorset stheali
gnmentofthedr opdown
cal
endarontheDat
eTimePi
ckercont
rol.

13 For
eCol
or Get
s orset
st he for
egr
ound col
orof t
he
Dat
eTi
mePi
ckercont
rol
.

14 For
mat Get
sorsetsthefor
matoft
hedat
eandt
ime
di
spl
ayedi
nthecont
rol
.

15 MaxDat
e Getsorsetst
hemaxi
mum dateandt
imet
hat
canbeselect
edi
nthecont
rol
.

CX
VB.
NET

16 Maxi
mumDat
eTi
me Get
sthemaxi
mum dateval
ueal
l
owedf
ort
he
Dat
eTi
mePi
ckercont
rol
.

17 Mi
nDat
e Getsorset
st hemini
mum dateandt
imet
hat
canbesel
ectedint
hecont
rol
.

18 Mi
nimumDat
eTi
me Get
sthemi
nimum dateval
ueal
l
owedf
ort
he
Dat
eTi
mePi
ckercont
rol
.

19 Pr
efer
redHei
ght Get
s t he pr ef
erred hei
ght of t
he
Dat
eTi
mePickercontr
ol.

20 Ri
ght
ToLef
tLay
out Get
s orsets whetherthe cont
ents oft
he
Dat
eTi
mePickerar
elaidoutf
rom r
ightt
olef
t.

21 ShowCheckBox Gets orsetsav al


ue i
ndicat
ing whet
hera
check box i
s di
spl
ayed t
ot he l
eftofthe
sel
ecteddat
e.

22 ShowUpDown Getsorsetsavalueindicat
ingwhetheraspi
n
butt
on contr
ol(also known as an updown
contr
ol)i
susedtoadjustthedat
e/ti
mev al
ue.

23 Text Getsorset
sthet
extassoci
atedwi
tht
his
contr
ol.

24 Val
ue Get
sorsetst
hedat
e/t
imev
alueassi
gnedt
o
t
hecont
rol
.

Met
hodsoft
heDat
eTi
mePi
ckerCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heDat
eTi
mePi
ckercont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 ToSt
ring
Ret
urnsthest
ri
ngr
epr
esent
ingt
hecont
rol
.

CXI
VB.
NET

Ev
ent
soft
heDat
eTi
mePi
ckerCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heDat
eTi
mePi
ckercont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 BackCol
orChanged
Occurs when the v al
ue of t
he
BackCol
orpr
oper
tychanges.

2 Backgr
oundI
mageChanged Occurswhent hev
alueofthe
BackgroundI
mage pr oper
ty
changes.

3 Backgr
oundI
mageLay
out
Changed Occurs when t he val
ue of the
BackgroundI
mageLay
out pr opert
y
changes.

4 Cl
ick Occur
swhent
hecont
rol
iscl
i
cked.

5 Cl
oseUp Occur
swhent hedrop-
downcal
endar
i
sdismissedanddi
sappear
s.

6 Doubl
eCl
ick Occurswhent
hecont
rol
isdoubl
e-
cl
icked.

7 Dr
agDr
op Occur
s when a dr ag-
and-
drop
oper
ati
oni
scompl
eted.

8 For
eCol
orChanged Occur
s when t he v alue of t
he
For
eColorpr
oper
tychanges.

9 For
mat
Changed Occur
s when t he For
mat pr
oper
ty
val
uehaschanged.

10 MouseCl
ick Occur
s when t
he cont
roli
s cl
i
cked
wit
hthemouse.

CXI
I
VB.
NET

11 MouseDoubl
eCl
ick Occurs when t
he cont
roli
s doubl
e-
cl
ickedwit
hthemouse.

12 Paddi
ngChanged Occur
swhent heval
ueoft
hePaddi
ng
pr
opert
ychanges.

13 Pai
nt Occur
swhent
hecont
rol
isr
edr
awn.

14 Ri
ght
ToLef
tLay
out
Changed Occurs when t
he
Right
ToLeft
Lay
out proper
ty
changes.

15 Text
Changed Occur
s when the v
alue oft
he Text
pr
opert
ychanges.

16 Val
ueChanged Occurswhent
heVal
uepr
oper
ty
changes.

Exampl
e

I
nthisexampl e,l
etuscr eat
easmal lappl
icat
ionforcal
culat
ingdaysofleave.Letusaddtwo
DateTimePickercontrolsontheform,wheretheuserwill
entert
hedateofgoi ngonleav
e
andthedat eofjoini
ng.Letuskeepabut t
oncontrolforperf
ormingthecalcul
ati
onand
appropri
atelabelcontrolsf
ordispl
ayi
nginfor
mation.
Thef
ormi
ndesi
gnv
iew:

Addt
hef
oll
owi
ngcodei
nthecodeedi
torwi
ndow:

Publ
i
cCl
assFor
m1
CXI
II
VB.
NET

Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspoi
nt.
com"
EndSub
Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
Di
m d1AsDat
eTi
me=Dat
eTi
mePi
cker
1.Val
ue
Di
m d2AsDat
eTi
me=Dat
eTi
mePi
cker
2.Val
ue
Di
mresul
tAsTi
meSpan=d1.
Subt
ract
(d2)
Di
m day
sAsI
nteger=r
esul
t.
Tot
alDay
s
Label
3.Text=day
s
EndSub
EndCl
ass

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

Sel
ectt
wodat
esandcl
i
ckont
hebut
tonf
orl
eav
ecal
cul
ati
on:

CXI
V
Di
alogBoxes
VB.
NET

Therearemanybuil
t-
indial
ogboxest obeusedinWi ndowsf ormsf orv ari
oust asksli
ke
openingandsav
ingf
il
es,pri
nti
ngapage,pr
ovi
dingchoi
cesforcolors,
fonts, pagesetup,et
c.,
totheuserofanappli
cati
on.Thesebuil
t-
indi
alogboxesreducet hedev eloper'
st i
meand
workl
oad.

Alloft
hesedial
ogboxcontrolcl
assesinher
itfrom t
heCommonDi al
ogcl
assandov
err
ide
theRunDi
alog(
)funct
ionoft
hebaseclasstocreatet
hespeci
fi
cdi
alogbox.

TheRunDial
og()funct
ioni
saut
omat
ical
l
yinv
okedwhenauserofadi
alogboxcal
l
sit
s
ShowDi
alog(
)functi
on.

TheShowDial
ogmethodisusedtodi
spl
ayal
lthedi
alogboxcontrol
satrun-t
ime.I
tret
urnsa
val
ueofthety
peofDial
ogResul
tenumer
ati
on.ThevaluesofDi
alogResul
tenumerat
ionare:

Abor
t-r
etur
nsDi
alogResul
t.
Abor
tval
ue,
whenusercl
i
cksanAbor
tbut
ton.

Cancel
-ret
urnsDi
alogResul
t.
Cancel
,whenusercl
i
cksaCancel
but
ton.

I
gnor
e-r
etur
nsDi
alogResul
t.
Ignor
e,whenusercl
i
cksanI
gnor
ebut
ton.

No-r
etur
nsDi
alogResul
t.
No,
whenusercl
i
cksaNobut
ton.

None-r
etur
nsnot
hingandt
hedi
alogboxcont
inuesr
unni
ng.

OK-r
etur
nsDi
alogResul
t.
OK,
whenusercl
i
cksanOKbut
ton

Ret
ry-r
etur
nsDi
alogResul
t.
Ret
ry,
whenusercl
i
cksaRet
rybut
ton

Yes-ret
urnsDi al
ogResul
t.
Yes,whenusercl
icksanYesbutt
on The
f
oll
owi
ngdi
agram showsthecommondi al
ogcl
assinher
it
ance:

Allt
heseabov
e-ment
ionedcl
asseshav
ecorr
espondingcontrol
sthatcoul
dbeaddedf r
om
theTool
boxduri
ngdesignt
ime.Youcani
ncl
uder el
evantfunct
ional
i
tyofthesecl
assesto

CXV
VB.
NET

yourappl
i
cat
ion,ei
therbyi
nst
ant
iat
ingt
hecl
asspr
ogr
ammat
ical
l
yorbyusi
ngr
elev
ant
cont
rol
s.

Wheny oudoubl
ecli
ckanyofthedi
alogcont
rol
sinthetool
boxordragthecont
rolont
ot he
for
m,itappear
sintheComponentt
rayatthebott
om oftheWindowsFormsDesigner
,they
donotdir
ectl
yshowupontheform.

Thefol
l
owingt
ablel
i
stst
hecommonl
yuseddi
alogboxcont
rol
s.Cl
i
ckt
hef
oll
owi
ngl
i
nkst
o
checkt
hei
rdet
ail
:
S.
N. Cont
rol&Descr
ipt
ion

1
Col
orDi
alog
Itrepresent
sacommon di al
og boxthatdi
splaysavai
l
abl
ecol
orsal
ong wi
th
control
sthatenabl
etheusertodef
inecust
om col
ors.

2
Font
Dial
og
Itpr
omptstheusertochooseaf ontfr
om amongt hoseinst
all
edont
hel
ocal
comput
erandlet
stheusersel
ectt
hefont
,fontsi
ze,
andcolor
.

OpenFi
l
eDi
alog
I
tpr
ompt
stheusert
oopenaf
il
eandal
l
owst
heusert
osel
ectaf
il
etoopen.

4
Sav
eFi
l
eDi
alog
Itpromptstheusertoselectal
ocat
ionforsav
ingaf
il
eandal
l
owst
heusert
o
specif
ythenameofthefi
letosav
edata.

Pr
int
Dial
og
Itlet
stheusertopri
ntdocument
sbyselect
ingapri
nterandchoosi
ngwhi
ch
secti
onsoft
hedocumentt
opri
ntfr
om aWi
ndowsFor
msappl i
cat
ion.

Col
orDi
alogCont
rol

TheColor
Dial
ogcont
rol
classr
epr
esent
sacommondial
ogboxthatdispl
aysav
ail
abl
ecolor
s
al
ongwi t
hcontr
olst
hatenabl
etheusert
odef
inecust
om col
ors.Itlet
stheusersel
ecta
col
or.

Themai
npr
oper
tyoft
heCol
orDi
alogcont
rol
isCol
or,
whi
chr
etur
nsaCol
orobj
ect
.
Fol
l
owi
ngi
stheCol
ordi
alogbox
:
CXVI
VB.
NET

Pr
oper
ti
esoft
heCol
orDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heCol
orDi
alogcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Al
lowFul
lOpen
Get
sorsetsaval
ueindi
cat
ingwhethert
heusercanuset
he
di
alogboxt
odefi
necust
om col
ors.

2 Any
Col
or Get
s orsetsav al
ue i
ndi
cat
ing whet
herthe di
alog box
di
spl
aysal
lavai
l
abl
ecol
orsi
nthesetofbasi
ccol
ors.

3 CanRai
seEv
ent
s Getsaval
uei
ndi
cat
ingwhet
hert
hecomponentcanr
aisean
event
.

4 Col
or Get
sorset
sthecol
orsel
ect
edbyt
heuser
.

5 Cust
omCol
ors Getsorset
sthesetofcust
om col
orsshowni
nthedi
alog
box.

6 Ful
lOpen Getsorset
sav al
ueindi
cat
ingwhethert
hecont
rolsusedt
o
creat
ecustom col
orsarev i
sibl
ewhent hedi
alogboxis
opened

CXVI
I
VB.
NET

7 ShowHel
p Gets orsetsav al
ue indi
cat
ing whet
hera Hel
p but
ton
appearsi
nthecol
ordi
alogbox.

8 Sol
idCol
orOnl
y Getsorsetsav al
uei
ndicat
ingwhetherthedi
alogboxwi
l
l
rest
ri
ctuser
stosel
ect
ingsol
idcol
orsonly
.

Met
hodsoft
heCol
orDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heCol
orDi
alogcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 Reset
Reset
sallopti
onstothei
rdefaultval
ues,t
hel
astsel
ect
edcol
ort
obl
ack,andt
he
cust
om col
orstothei
rdef
aul
tvalues.

2 RunDi
alog
Whenov er
ri
ddeni
nader
ivedcl
ass,
speci
fi
esacommondi
alogbox.

3 ShowDi
alog
Runsacommondi
alogboxwi
thadef
aul
towner
.

Ev
ent
soft
heCol
orDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heCol
orDi
alogcont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 Hel
pRequest
Occurswhent
heusercl
i
ckst
heHel
pbut
tononacommon
di
alogbox.

Exampl
e

I
nthi
sexampl
e,l
et'
schanget
hef
orecol
orofal
abelcont
rolusi
ngt
hecol
ordi
alogbox.Take
t
hefol
lowi
ngst
eps:

• Dr
aganddr
opal
abel
cont
rol
,abut
toncont
rol
andaCol
orDi
alogcont
rol
ont
hef
orm.

• Sett
heTextpr
opert
yoft helabelandt
hebut
toncont
rolt
o'Gi
vemeanewCol
or'
and
'
ChangeCol
or'
,r
espect
ively
.

CXVI
II
VB.
NET

• Changet
hef
ontoft
hel
abel
aspery
ourl
i
kings.

• Doubl
e-cl
i
ckt
heChangeCol
orbut
tonandmodi
fyt
hecodeoft
heCl
i
ckev
ent
.

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
I
fCol
orDi
alog1.
ShowDi
alog<>Wi
ndows.
For
ms.
Dial
ogResul
t.
Cancel
Then
Label
1.For
eCol
or=Col
orDi
alog1.
Col
or
EndI
fEnd
Sub

Whentheappl
i
cationiscompi
ledandrunusi
ngStar
tbut
tonav
ail
abl
eatt
heMi
crosof
tVi
sual
St
udi
ot ool
bar
,itwil
lshowthefol
lowi
ngwindow:

Cli
cki
ngontheChangeCol
orbut
ton,t
hecolordi
alogappears,sel
ectacolorandcli
ckt
heOK
butt
on.Thesel
ect
edcol
orwil
lbeappl
iedastheforecol
orofthetextoft
helabel.

Font
Dial
ogCont
rol

I
tpromptstheusertochooseafontfr
om amongthoseinst
all
edonthelocalcomput
erand
l
etstheusersel
ectt
hefont,f
ontsi
ze,
andcolor
.Itr
etur
nstheFontandColorobj
ect
s.
Fol
l
owi
ngi
stheFontdi
alogbox
:

CXI
X
VB.
NET

Bydefaul
t,t
heColorComboBoxi snotshownontheFontdi
alogbox.Youshoul
dsett
he
ShowColorpr
oper
tyoftheFont
Dial
ogcontrol
tobeTr
ue.
Pr
oper
ti
esoft
heFont
Dial
ogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heFont
Dial
ogcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Al
lowSi
mul
ati
ons
Getsorset
sav al
ueindi
cati
ngwhetherthedi
alogbox
al
lowsgr
aphicsdevi
ceint
erf
ace(
GDI)fontsi
mul
ations.

2 Al
lowVect
orFont
s Getsorsetsavalueindi
cat
ingwhet
hert
hedi
alogbox
al
lowsvect
orf
ontsel
ecti
ons.

3 Al
lowVer
ti
cal
Font
s Get
sorset sav al
ueindi
cat
ingwhethert
hedial
ogbox
di
splays bothv er
ti
caland hor
izont
alfont
s,oronly
hor
izontalf
onts.

4 Col
or Get
sorset
sthesel
ect
edf
ontcol
or.

5 Fi
xedPi
tchOnl
y Getsorsetsav alueindi
cat
ingwhetherthedi
alogbox
al
lowsonl
ytheselect
ionoffi
xed-
pit
chfont
s.

CXX
VB.
NET

6 Font Get
sorset
sthesel
ect
edf
ont
.

7 Font
Must
Exi
st Getsorsetsav alueindicat
ingwhetherthedi
alogbox
speci
fi
esanerrorcondit
ioniftheuserat
tempt
stosel
ect
afontorst
ylet
hatdoesnotexi st.

8 MaxSi
ze Get
sorset
sthemaxi
mum poi
ntsi
zeausercansel
ect
.

9 Mi
nSi
ze Get
sorset
sthemi
nimum poi
ntsi
zeausercansel
ect
.

10 Scr
ipt
sOnl
y Getsorsetsav al
ueindi
cati
ngwhetherthedi
alogbox
al
lowsselect
ionoffontsforal
lnon-OEM andSymbol
char
act
ersets,aswel
lastheANSIchar
act
erset
.

11 ShowAppl
y Getsorsetsav al
ueindi
cat
ingwhet
hert
hedi
alogbox
cont
ainsanAppl
ybutt
on.

12 ShowCol
or Get
sorsetsav al
ueindi
cat
ingwhet
hert
hedi
alogbox
di
spl
ayst
hecol
orchoi
ce.

13 ShowEf
fect
s Getsorset sav al
ueindicat
ingwhetherthedial
ogbox
contai
ns control
s that all
ow t he user to speci
fy
str
iket
hrough,
underl
ine,
andt extcol
oropt
ions.

14 ShowHel
p Get
sorsetsaval
ueindi
cat
ingwhet
hert
hedi
alogbox
di
spl
aysaHel
pbut
ton.

Met
hodsoft
heFont
Dial
ogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heFont
Dial
ogcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 Reset
Reset
sal
lopt
ionst
othei
rdef
aul
tval
ues.

CXXI
VB.
NET

2 RunDi
alog
Whenov
err
iddeni
nader
ivedcl
ass,
speci
fi
esacommondi
alogbox.

3 ShowDi
alog
Runsacommondi
alogboxwi
thadef
aul
towner
.

Ev
ent
soft
heFont
Dial
ogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heFont
Dial
ogcont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 Appl
y
Occurswhent
heAppl
ybut
tonont
hef
ontdi
alogboxi
s
cl
icked.

Exampl
e

I
nt hi
sexample,l
et'
schangethefontandcol
oroft
het
extf
rom ar
icht
extcont
rolusi
ngt
he
Fontdial
ogbox.Taket
hefoll
owingsteps:

• Draganddr
opaRi
chText
Boxcont
rol
,aBut
toncont
rolandaFont
Dial
ogcont
rolon
thefor
m.

• Sett
heTextpr
oper
tyoft
hebut
toncont
rol
to'
ChangeFont
'.

• Sett
heShowCol
orpr
oper
tyoft
heFont
Dial
ogcont
rol
toTr
ue.

Doubl
e-cl
i
ckt
heChangeCol
orbut
tonandmodi
fyt
hecodeoft
heCl
i
ckev
ent
:
Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
I
fFont
Dial
og1.
ShowDi
alog<>Wi
ndows.
For
ms.
Dial
ogResul
t.
Cancel
Then
Ri
chText
Box1.
For
eCol
or=Font
Dial
og1.
Col
or
Ri
chText
Box1.
Font=Font
Dial
og1.
Font
EndI
f
EndSub

Whentheappl
i
cationiscompi
ledandrunusi
ngStar
tbut
tonav
ail
abl
eatt
heMi
crosof
tVi
sual
St
udi
ot ool
bar
,itwil
lshowthefol
lowi
ngwindow:

CXXI
I
VB.
NET

Ent
ersomet
extandCl
i
ckont
heChangeFontbut
ton.

TheFontdi
alogappears,
sel
ectafontandacol
orandcli
cktheOKbutton.Theselect
edf
ont
andcol
orwil
l beappl
i
edasthefontandfor
ecol
orofthetextoft
her
ichtextbox.

CXXI
II
VB.
NET

OpenFi
l
eDi
alogCont
rol

TheOpenFil
eDi
alogcontr
olpromptstheusertoopenafil
eandallowstheusertoselecta
fi
let
oopen.Theusercancheckift
hefil
eexi
stsandthenopeni
t.TheOpenFi
leDi
alogcontrol
cl
assinher
it
sfr
om theabstr
actcl
assFil
eDi
alog.

I
ftheShowReadOnlypr
oper
tyissett
oTrue,t
henar ead-
onl
ycheckboxappearsinthedi
alog
box.YoucanalsosettheReadOnly
Checkedpropertyt
oTrue,sothatt
her ead-
onlycheck
boxappear
schecked.
Fol
l
owi
ngi
stheOpenFi
l
edi
alogbox
:

Pr
oper
ti
esoft
heOpenFi
l
eDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heOpenFi
l
eDi
alogcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 AddExt
ensi
on
Getsorset sav al
ueindicat
ingwhether
the dial
og box aut
omatical
ly adds an
extensi
ontoaf i
l
enamei ftheuseromits
theextensi
on.

CXXI
V
VB.
NET

2 Aut
oUpgr
adeEnabl
ed Getsorsetsav al
ueindicati
ngwhet her
thi
s Fi l
eDial
og i
nstance should
automati
cal
ly upgrade appear ance and
behavi
orwhenr unni
ngonWi ndowsVi sta.

3 CheckFi
leExi
sts Getsorsetsavalueindi
cati
ngwhether
thedial
ogboxdi
splay
sawar ni
ngifthe
userspeci
fi
esaf
il
enamet hatdoesnot
exi
st.

4 CheckPat
hExi
sts Getsorset saval
ueindicat
ingwhether
thedial
ogboxdispl
aysawar ni
ngifthe
userspeci
fi
esapat
hthatdoesnotexi
st.

5 Cust
omPl
aces Getsthecust
om placescol
l
ect
ionf
ort
his
Fi
leDi
alogi
nstance.

6 Def
aul
tExt Getsorsetst
hedef
aul
tfi
l
ename
ext
ension.

7 Der
efer
enceLi
nks Getsorset sav alueindi
cati
ngwhet her
t
hedi alogboxr et
urnsthelocati
onoft he
fi
l
er eferencedbytheshortcutorwhether
i
tr eturns the l
ocati
on oft he shor
tcut
(.
lnk)
.

8 Fi
l
eName Getsorset
sastri
ngcontaini
ngthef
il
e
namesel
ect
edi
nthefi
l
edialogbox.

9 Fi
leNames Get
st hefi
lenamesofal
lsel
ect
edf
il
esi
n
t
hedialogbox.

10 Fi
lt
er Getsorset st
hecur rentfi
lenamef i
l
ter
str
ing,whichdeter
mi nesthechoicesthat
appearint he"
Saveasf i
letype"or"Fi
les
oftype"boxinthedialogbox.

CXXV
VB.
NET

11 Fi
lt
erI
ndex Get
s or setst he i
ndex of t
he f
il
ter
cur
rent
lysel
ect
edinthefi
l
edial
ogbox
.

12 I
nit
ial
Dir
ect
ory Get
sorset
stheini
ti
aldi
rect
orydi
spl
ayed
byt
hef
il
edial
ogbox.

13 Mul
ti
sel
ect Getsorsetsavaluei
ndi
cat
ingwhet
her
thedi
alogboxal
l
owsmult
ipl
efil
est
obe
sel
ect
ed.

14 ReadOnl
yChecked Get
sorsetsav al
ueindi
cat
ingwhet
her
t
heread-
onl
ycheckboxissel
ect
ed.

15 Rest
oreDi
rect
ory Getsorsetsav al
uei ndicat
ingwhether
the di
alog box restor
es t he cur
rent
dir
ect
orybef
orecl
osing.

16 Saf
eFi
leName Getsthefil
enameandext ensi
onf
ort
he
fi
leselect
edinthedialogbox.Thef
il
e
namedoesnotincl
udethepath.

17 Saf
eFi
leNames Gets an ar r
ay of f i
l
e names and
extensi
onsf
orallthesel
ect
edf
il
esinthe
dial
ogbox.Thefil
enamesdonotincl
ude
thepath.

18 ShowHel
p Getsorsetsav al
ueindicat
ingwhet
her
theHelp but
tonisdi
splayed i
nthefi
le
dial
ogbox.

19 ShowReadOnl
y Getsorsetsav al
uei ndi
cat
ingwhether
thedi
alogboxcont
ainsaread-onl
ycheck
box.

20 Suppor
tMul
ti
Dot
tedExt
ensi
ons Gets orset s whet
herthe di
alog box
support
sdisplayi
ngandsavi
ngfilest
hat
havemulti
plefil
enameext
ensi
ons.

CXXVI
VB.
NET

21 Ti
tl
e Get
sorset
sthef
il
edi
alogboxt
it
le.

22 Val
idat
eNames Getsorset
savalueindi
cat
ingwhet
her
t
hedial
ogboxaccept
sonlyv al
i
dWin32
fi
l
enames.

Met
hodsoft
heOpenFi
l
eDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heOpenFi
l
eDi
alogcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 OpenFi
le
Opensthefi
lesel
ect
edbytheuser
,wi
thr
ead-
onl
yper
missi
on.Thef
il
eisspeci
fi
ed
bytheFil
eNameproper
ty.

2 Reset
Reset
sal
lopt
ionst
othei
rdef
aul
tval
ue.

Exampl
e

I
nthi
sexample,l
et'
sloadani
magef
il
einapi
ctur
ebox
,usi
ngt
heopenf
il
edi
alogbox.Take
t
hefol
lowi
ngsteps:

• Draganddr
opaPi
ctur
eBoxcont
rol
,aBut
toncont
rolandaOpenFi
l
eDi
alogcont
rolon
thefor
m.

• SettheTextpr
oper
tyofthebut
toncont
rol
to'
LoadImageFil
e'
.
• Doubl
e-cl
i
cktheLoadImageFi
lebutt
onandmodifyt
hecodeoftheCli
ckev
ent
.

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
I
fOpenFi
l
eDi
alog1.
ShowDi
alog<>Wi
ndows.
For
ms.
Dial
ogResul
t.
Cancel
Then
Pi
ctur
eBox
1.I
mage=I
mage.
FromFi
l
e(OpenFi
l
eDi
alog1.
Fil
eName)
EndI
f
EndSub

Whentheappl
i
cationiscompi
ledandrunusi
ngStar
tbut
tonav
ail
abl
eatt
heMi
crosof
tVi
sual
St
udi
ot ool
bar
,itwil
lshowthefol
lowi
ngwindow:

CXXVI
I
VB.
NET

Cl
i
ckont
heLoadI
mageFi
l
ebut
tont
oloadani
magest
oredi
nyourcomput
er.

Sav
eFi
l
eDi
alogCont
rol

TheSaveFil
eDial
ogcontr
olpromptstheusert
osel
ectalocat
ionf
orsavi
ngafi
leandall
ows
theusertospecifythenameoft hefi
letosavedat
a.TheSav eFi
l
eDial
ogcontr
olcl
ass
i
nheri
tsfr
om theabst
ractcl
assFil
eDial
og.
Fol
l
owi
ngi
stheSav
eFi
l
edi
alogbox:

CXXVI
II
VB.
NET

Pr
oper
ti
esoft
heSav
eFi
l
eDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heSav
eFi
l
eDi
alogcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 AddExt
ensi
on
Getsorset sav al
ueindicat
ingwhether
the dial
og box aut
omatical
ly adds an
extensi
ontoaf i
l
enamei ftheuseromits
theextensi
on.

2 CheckFi
leExi
sts Getsorsetsavalueindi
cati
ngwhether
thedial
ogboxdi
splay
sawar ni
ngifthe
userspeci
fi
esaf
il
enamet hatdoesnot
exi
st.

3 CheckPat
hExi
sts Getsorset saval
ueindicat
ingwhet her
thedial
ogboxdispl
aysawar ni
ngift he
userspeci
fi
esapat
hthatdoesnotexist.

CXXI
X
VB.
NET

4 Cr
eat
ePr
ompt Getsorsetsav al
ueindi
cati
ngwhet her
the dial
og box prompt
st he user for
permissi
on t
o createaf i
l
ei fthe user
speci
fiesaf
il
ethatdoesnotexi
st.

5 Def
aul
tExt Getsorsetst
hedef
aul
tfi
l
ename
ext
ension.

6 Der
efer
enceLi
nks Getsorset sav alueindi
cati
ngwhet her
t
hedi alogboxr et
urnsthelocati
onoft he
fi
l
er eferencedbytheshortcutorwhether
i
tr eturns the l
ocati
on oft he shor
tcut
(.
lnk)
.

7 Fi
leName Getsorset
sastri
ngcontaini
ngthef
il
e
namesel
ect
edi
nthefi
l
edialogbox.

8 Fi
leNames Get
st hefi
lenamesofal
lsel
ect
edf
il
esi
n
t
hedialogbox.

9 Fi
lt
er Getsorset st
hecur rentfi
lenamef i
l
ter
str
ing,whichdeter
mi nesthechoicesthat
appearint he"
Saveasf i
letype"or"Fi
les
oftype"boxinthedialogbox.

10 Fi
lt
erI
ndex Get
s or setst he i
ndex of t
he f
il
ter
cur
rent
lysel
ect
edinthefi
l
edial
ogbox
.

11 I
nit
ial
Dir
ect
ory Get
sorset
stheini
ti
aldi
rect
orydi
spl
ayed
byt
hef
il
edial
ogbox.

12 Ov
erwr
it
ePr
ompt Get
sorsetsavaluei
ndi
cat
ingwhet
hert
he
Sav
eAsdialogbox

di
spl
aysawarni
ngi ft
heuserspeci
fi
esa
fi
l
enamethatal
readyexi
sts.

CXXX
VB.
NET

13 Rest
oreDi
rect
ory Getsorsetsav al
uei ndicat
ingwhether
the di
alog box restor
es t he cur
rent
dir
ect
orybef
orecl
osing.

14 ShowHel
p Getsorsetsav al
ueindicat
ingwhet
her
theHelp but
tonisdi
splayed i
nthefi
le
dial
ogbox.

15 Suppor
tMul
ti
Dot
tedExt
ensi
ons Gets orset s whet
herthe di
alog box
support
sdisplayi
ngandsavi
ngfilest
hat
havemulti
plefil
enameext
ensi
ons.

16 Ti
tl
e Get
sorset
sthef
il
edi
alogboxt
it
le.

17 Val
idat
eNames Getsorset
savalueindi
cat
ingwhet
her
t
hedial
ogboxaccept
sonlyv al
i
dWin32
fi
l
enames.

CXXXI
VB.
NET

Met
hodsoft
heSav
eFi
l
eDi
alogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
heSav
eFi
l
eDi
alogcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 OpenFi
le
Opensthef
il
ewi
thr
ead/
wri
teper
missi
on.

2 Reset
Reset
sal
ldi
alogboxopt
ionst
othei
rdef
aul
tval
ues.

Exampl
e

I
nthisexample,l
et'
ssavet
het
extent
eredi
ntoar
icht
extboxbyt
heuserusi
ngt
hesav
efi
l
e
di
alogbox.Takethefol
l
owi
ngst
eps:

• Drag and drop a Labelcont


rol
,a Ri
chText
Boxcont
rol
,a But
ton cont
roland a
SaveFi
leDi
alogcontrolont
heform.

• Sett
heTextproper
tyoft
helabelandt hebutt
oncont
rolt
o'Weappr
eci
atey
our
comment
s'and'
SaveComment
s',
respect
ivel
y.

• Doubl
e-cl
i
ckt
heSav
eComment
sbut
tonandmodi
fyt
hecodeoft
heCl
i
ckev
entas
shown:

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
Sav
eFi
l
eDi
alog1.
Fil
ter="
TXTFi
l
es(
*.t
xt*
)|*
.txt
"
I
fSav
eFi
l
eDi
alog1.
ShowDi
alog=Wi
ndows.
For
ms.
Dial
ogResul
t.
OK_
Then
My
.Comput
er.
Fil
eSy
stem.
Wri
teAl
l
Text_
(
Sav
eFi
l
eDi
alog1.
Fil
eName,
RichText
Box
1.Text
,Tr
ue)
EndI
f
EndSub

Whentheappl
i
cationiscompi
ledandrunusi
ngStar
tbut
tonav
ail
abl
eatt
heMi
crosof
tVi
sual
St
udi
ot ool
bar
,itwil
lshowthefol
l
owingwindow:

CXXXI
I
VB.
NET

WehavesettheFil
terpr
oper
tyoft
heSav
eFi
l
eDi
alogcont
rol
todi
spl
ayt
extf
il
ety
peswi
th.
txt
ext
ensi
onsonly.

Wri
tesometextint
hetextboxandcl
i
ckont
heSav
eCommentbut
tont
osav
ethet
extasa
t
extfi
l
einyourcomput
er.

Pr
int
Dial
ogCont
rol

ThePrint
Dial
ogcont r
olletstheusert opr
intdocumentsbyselecti
ngapr i
nterandchoosi
ng
whichsecti
onsofthedocumentt opri
ntfr
om aWi ndowsFormsappl i
cat
ion.
Therearevari
ousothercont r
olsrel
atedtoprint
ingofdocuments.Letushaveabr i
efl
ookat
thesecont
rolsandtheirpurpose.Theseothercontr
olsar
e:

• ThePrint
Documentcont
rol-i
tpr
ovi
dessuppor
tforactualev
ent
sandoper
ati
onsof
pri
nti
nginVi
sualBasi
candset
sthepr
oper
tiesf
orpri
nti
ng.

• ThePrinter
Set
ti
ngscont
rol-i
tisusedt
oconf
igur
ehow adocumenti
spr
int
edby
speci
fyi
ngthepri
nter
.

• The PageSet
UpDialog contr
ol-itall
owst he userto speci
fypage-
rel
ated pr
int
set
ti
ngsincl
udingpageorient
ati
on,
papersi
zeandmar gi
nsize.

• The Pri
ntPr
evi
ewContr
olcont
rol-i
tr epresent
sthe raw prev
iew partofpr i
nt
prev
iewi
ngfrom aWi
ndowsFor
msappl
icati
on,wit
houtanydi
alogboxesorbut
tons.

• ThePrint
Prev
iewDial
ogcont r
ol-itr
epr
esentsadial
ogboxformt hatcont
ainsa
Pri
ntPr
evi
ewContr
ol f
orpr
int
ingfr
om aWindowsFor
msappl
icat
ion.
Fol
l
owi
ngi
sthePr
intdi
alogbox:

CXXXI
II
VB.
NET

Pr
oper
ti
esoft
hePr
int
Dial
ogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
hePr
int
Dial
ogcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Al
lowCur
rent
Page
Gets orsetsav alue i
ndicat
ing whet
hert
he Cur
rent
Pageopt
ionbut
toni
sdispl
ayed.

2 Al
lowPr
int
ToFi
le Getsorset
saval
ueindicat
ingwhet
hert
hePr
intt
o
fi
l
echeckboxi
senabled.

3 Al
lowSel
ect
ion Get
s orsetsav al
ue i
ndi
cat
ing whet
hert
he Sel
ect
ion
opt
ionbut
toni
senabl
ed.

4 Al
lowSomePages Get
sorsetsav al
uei
ndi
cat
ingwhet
hert
hePagesopt
ion
but
toni
senabl
ed.

CXXXI
V
VB.
NET

5 Document Get
sorsetsav al
uei ndi
cat
ingt
hePr
int
Documentusedt
o
obt
ainPr
int
erSett
ings.

6 Pr
int
erSet
ti
ngs Get
sorset
sthepr
int
erset
ti
ngst
hedi
alogboxmodi
fi
es.

7 Pr
int
ToFi
le Getsorset
saval
ueindi
cati
ngwhet
hert
hePr
intt
o
fi
l
echeckboxi
ssel
ected.

8 ShowHel
p Get
sorsetsav
aluei
ndi
cat
ingwhet
hert
heHel
pbut
toni
s
di
spl
ayed.

9 ShowNet
wor
k Get
sorsetsaval
uei
ndi
cat
ingwhet
hert
heNet
wor
kbut
ton
i
sdispl
ayed.

Met
hodsoft
hePr
int
Dial
ogCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedmet
hodsoft
hePr
int
Dial
ogcont
rol
:

S.
N Met
hodName&Descr
ipt
ion

1 Reset
Reset
sal
lopt
ionst
othei
rdef
aul
tval
ues.

2 RunDi
alog
Whenov er
ri
ddeni
nader
ivedcl
ass,
speci
fi
esacommondi
alogbox.

3 ShowDi
alog
Runsacommondi
alogboxwi
thadef
aul
towner
.

CXXXV
VB.
NET

Exampl
e

I
nthi
sexampl
e,l
etusseehowt
oshowaPr
intdi
alogboxi
naf
orm.Taket
hef
oll
owi
ngst
eps:

• AddaPr i
ntDocumentcontr
ol,
aPr i
ntDi
alogcont
rolandaBut
toncont
rolont
heform.
ThePrintDocumentandthePrint
Dial
ogcontrol
sarefoundonthePri
ntcat
egoryof
thecontr
olstool
box.

• Changet
het
extoft
hebut
tont
o'Pr
int
'.

• Doubl
e-cl
i
ckt
hePr
intbut
tonandmodi
fyt
hecodeoft
heCl
i
ckev
entasshown:

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esBut
ton1.
Cli
ck
Pr
int
Dial
og1.
Document=Pr
int
Document
1
Pr
int
Dial
og1.
Pri
nter
Set
ti
ngs=Pr
int
Document
1.Pr
int
erSet
ti
ngs
Pr
int
Dial
og1.
All
owSomePages=Tr
ue
I
fPr
int
Dial
og1.
ShowDi
alog=Di
alogResul
t.
OKThen
Pr
int
Document
1.Pr
int
erSet
ti
ngs=Pr
int
Dial
og1.
Pri
nter
Set
ti
ngs
Pr
int
Document
1.Pr
int
()
EndI
fEnd
Sub

• When the appli


cat
ion i
s compiled and run usi
ng St
artbutt
on av
ail
abl
e att
he
Mi
crosoftVisual
Studi
otoolbar
,itwil
l showthefol
lowi
ngwindow:

• Cl
i
ckt
hePr
intbut
tont
omaket
hePr
intdi
alogboxappear
.

CXXXVI
Adv
ancedFor
m
VB.
NET

I
nthi
schapt
er,
letusst
udyt
hef
oll
owi
ngconcept
s:

• Addi
ngmenusandsubmenusi
nanappl
i
cat
ion

• Addi
ngt
hecut
,copyandpast
efunct
ional
i
tiesi
naf
orm

• Anchor
inganddocki
ngcont
rol
sinaf
orm

• Modal
for
ms

Addi
ngMenusandSubMenusi
nanAppl
i
cat
ion

Tradit
ional
l
y he Menu,Mai
,t nMenu,Context
Menu,and MenuIt
em classeswer
eusedf
or
addingmenus,sub-
menusandcontextmenusinaWindowsappl
icat
ion.

Now, theMenuSt r
ip, t
heToolSt r
ipMenuI t
em,ToolStr
ipDropDownand
ToolStripDropDownMenu cont rol
sr eplace and add functi
onali
tyt ot he Menur elated
controlsofpr ev i
ousv er
sions.Howev er,t
heold controlclassesar eretained f
orbot h
backwar dcompat ibili
tyandfutureuse.
Letuscr eateat ypicalwindowsmai nmenubarandsubmenususi ngt heoldv ersion
controlsfir
stsincet hesecontrol
sar estil
lmuchusedi noldappli
cat
ions.

Foll
owi
ngisanexampl
e,whi
chshowshowwecreat
eamenubarwi
thmenui
tems:
Fil
e,Edi
t,
ViewandProj
ect
.TheFi
lemenuhast
hesubmenusNew,
OpenandSave.
Let
'sdoubl
ecl
i
ckont
heFor
m andputt
hef
oll
owi
ngcodei
ntheopenedwi
ndow.

Publ
i
cCl
assFor
m1
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
esMy
Base.
Load
'
def
ini
ngt
hemai
nmenubar
Di
m mnuBarAsNewMai
nMenu(
)
'
def
ini
ngt
hemenui
temsf
ort
hemai
nmenubar
Di
m my
MenuI
temFi
l
eAsNewMenuI
tem(
"&Fi
l
e")
Di
m my
MenuI
temEdi
tAsNewMenuI
tem(
"&Edi
t"
)
Di
m my
MenuI
temVi
ewAsNewMenuI
tem(
"&Vi
ew"
)
Di
m my
MenuI
temPr
ojectAsNewMenuI
tem(
"&Pr
oject
")
'
addi
ngt
hemenui
temst
othemai
nmenubar

mnuBar
.MenuI
tems.
Add(
myMenuI
temFi
l
e)

CXXXVI
I
VB.
NET

mnuBar
.MenuI
tems.
Add(
myMenuI
temEdi
t)
mnuBar
.MenuI
tems.
Add(
myMenuI
temVi
ew)
mnuBar
.MenuI
tems.
Add(
myMenuI
temPr
oject
)

'
def
ini
ngsomesubmenus
Di
m my
MenuI
temNewAsNewMenuI
tem(
"&New"
)
Di
m my
MenuI
temOpenAsNewMenuI
tem(
"&Open"
) Di
m my
MenuI
temSav
eAs
NewMenuI
tem(
"&Sav
e")

'
addsubmenust
otheFi
l
emenu
my
MenuI
temFi
l
e.MenuI
tems.
Add(
myMenuI
temNew)
my
MenuI
temFi
l
e.MenuI
tems.
Add(
myMenuI
temOpen)
my
MenuI
temFi
l
e.MenuI
tems.
Add(
myMenuI
temSav
e)

'
addt
hemai
nmenut
othef
orm
Me.
Menu=mnuBar

'
Sett
hecapt
ionbart
extoft
hef
orm.
Me.
Text="
tut
ori
alspoi
nt.
com"
EndSub
EndCl
ass

Whentheabovecodeisexecut
edandrunusi
ngStar
tbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowthef
oll
owi
ngwindow:

Wi
ndowsFor
mscont
ainar
ichsetofcl
assesf
orcr
eat
ingy
ourowncust
om menuswi
th

CXXXVI
II
VB.
NET

modernappearance,lookandfeel.TheMenuSt ri
p,Tool
Str
ipMenuItem,Cont
ext
MenuSt
ri
p
contr
olsareusedtocreatemenubar sandcontextmenuseffi
cient
ly.
Cli
ckthefoll
owingl
inkstochecktheirdet
ail
s:

S.
N. Cont
rol&Descr
ipt
ion

1 MenuStr
ip
I
tprovi
desamenusy
stem f
oraf
orm.

2 ToolSt r
ipMenuI
tem
Itr
epr esentsasel
ectabl
eopti
ondisplay
edonaMenuStr
iporContext
MenuSt
rip.
TheTool St
ri
pMenuIt
em cont
rolr
eplacesandaddsf
unct
ional
i
tyt
ot heMenuI
tem
controlofprevi
ousversi
ons.

3 ContextMenuSt
ri
p
I
trepresent
sashort
cutmenu.

MenuSt
ri
pCont
rol

TheMenuStri
pcontrolrepresentsthecontai
nerforthemenust ructur
e.TheMenuSt r
ip
cont
rolwor
ksast hetop-levelcont
ainerf
orthemenust r
ucture.TheToolStr
ipMenuI
tem
cl
assandtheToolStri
pDropDownMenucl assprovidethef uncti
onali
ti
estocreat
emenu
i
tems,submenusanddrop- downmenus.Thefoll
owingdiagram showsaddingaMenuSt r
ip
cont
rolont
hefor
m:

CXXXI
X
VB.
NET

Pr
oper
ti
esoft
heMenuSt
ri
pCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heMenuSt
ri
pcont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 CanOv
erf
low
Getsorset
sav al
uei ndi
cat
ingwhet
hert
heMenuSt
ri
p
suppor
tsov
erf
lowfuncti
onal
it
y.

2 Gr
ipSt
yle Get
sorsetst
hev
isi
bil
i
tyoft
hegr
ipusedt
oreposi
ti
on
t
hecont
rol
.

3 Mdi
WindowLi
stI
tem GetsorsetstheToolStr
ipMenuI
tem thati
susedto
displ
ayal
i
stofMul
ti
ple-documenti
nter
face(
MDI)chi
l
d
forms.

CXL
VB.
NET

4 ShowI
temTool
Tips Getsorsetsavalueindi
cat
ingwhet
herTool
Tipsar
e
shownfort
heMenuStr
ip.

5 St
ret
ch Getsorsetsav al
ueindi
cati
ngwhethertheMenuSt
ri
p
st
retchesf
rom endtoendini
tscont
ainer
.

Ev
ent
soft
heMenuSt
ri
pCont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heMenuSt
ri
pcont
rol
:

S.
N Ev
ent Descr
ipt
ion

1 MenuAct
ivat
e
Occur
swhent
heuseraccessest
hemenuwi
tht
hekey
boar
d
ormouse.

2 MenuDeact
ivat
e Occur
swhent
heMenuSt
ri
pisdeact
ivat
ed.

Exampl
e

I
nthi
sexampl
e,l
etusaddmenuandsub-
menui
tems.
Taket
hef
oll
owi
ngst
eps:

• Dr
aganddr
opordoubl
ecl
i
ckonaMenuSt
ri
pcont
rol
,toaddi
ttot
hef
orm.

• Cli
cktheTypeHeretexttoopenat
extboxandent
ert
henamesofthemenui
temsor
sub-menuitemsyouwant .Whenyouaddasub-menu,anot
hert
extboxwi
th'
Type
Here't
extopensbel
owi t
.

• Compl
etet
hemenust
ruct
ureshowni
nthedi
agr
am abov
e.

• AddasubmenuExi
tundert
heFi
lemenu.

CXLI
VB.
NET

• Double-
Cli
cktheExi
tmenucr
eat
edandaddt
hef
oll
owi
ngcodet
otheCl
ickev
entof
Exi
tToolSt
ri
pMenuIt
em:

Pr
ivat
eSubExi
tTool
Str
ipMenuI
tem_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esEx
itTool
Str
ipMenuI
tem.
Cli
ck
End
EndSub

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

Cl
i
ckont
heFi
l
e->Exi
ttoexi
tfr
om t
heappl
i
cat
ion:

CXLI
I
VB.
NET

St
ri
pMenuI
tem Cont
rol

TheTool
Str
ipMenuI
tem cl
asssuppor
tst
hemenusandmenui
temsi
namenusy
stem.You

handl
ethesemenui
temst
hrought
hecl
i
ckev
ent
sinamenusy
stem. Pr
oper
ti
esof
t
heTool
Str
ipMenuI
tem Cont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedpr
oper
ti
esoft
heTool
Str
ipMenuI
tem cont
rol
:

S.
N Pr
oper
ty Descr
ipt
ion

1 Checked
Gets orset
sav alue i
ndi
cati
ng whet
hert
he
Tool
Stri
pMenuI
tem i
schecked.

2 CheckOnCl
ick Gets orsetsav alue i
ndi
cati
ng whetherthe
ToolStr
ipMenuI
tem shoul
dautomatical
l
yappear
checkedanduncheckedwhenclicked.

3 CheckSt
ate Gets orset sav al
ue indicat
ing whet
hera
ToolSt
ripMenuI
tem i s i n t he checked,
unchecked,ori
ndet
erminatestat
e.

4 Enabl
ed Gets orset
sav al
ue i
ndi
cat
ing whet
hert
he
cont
roli
senabl
ed.

CXLI
II
VB.
NET

5 I
sMdi
WindowLi
stEnt
ry Gets a v al
ue i ndi
cat
ing whet
her the
ToolSt
ri
pMenuI
tem appears on a mul
ti
ple
documenti
nter
face(
MDI)windowl
i
st.

6 Shor
tcut
Key
Displ
aySt
ri
ng Get
sorset
stheshor
tcutkeyt
ext
.

7 Shor
tcut
Key
s Get
sorsetstheshort
cutkey
sassoci
atedwi
th
t
heTool
Str
ipMenuI
tem.

8 ShowShor
tcut
Key
s Gets orset
sav al
ue indicati
ng whet
hert
he
shor
tcutkeyst hatar e associat
ed witht
he
Tool
Stri
pMenuI
tem ar e display
ed nexttot
he
Tool
Stri
pMenuI
tem.

Ev
ent
soft
heTool
Str
ipMenuI
tem Cont
rol

Thef
oll
owi
ngar
esomeoft
hecommonl
yusedev
ent
soft
heTool
Str
ipMenuI
tem cont
rol
:
S.
N Ev
ent Descr
ipt
ion

1 CheckedChanged
Occurswhent
hev
alueoft
heCheckedpr
oper
ty
changes.

2 CheckSt
ateChanged Occurswhent
hev
alueoft
heCheckSt
atepr
oper
ty
changes.

Exampl
e

I
nt hi
sexampl e,l
etuscont
inuewi
tht
heexampl
efr
om t
hechapt
er'
VB.
Net-MenuSt
ri
p
contr
ol'
.Letus:

• Hi
deanddi
spl
aymenui
tems.

• Di
sabl
eandenabl
emenui
tems.

• Setaccesskey
sformenui
tems

• Setshor
tcutkey
sformenui
tems.

Hi
deandDi
spl
ayMenuI
tems
TheVisi
blepr
opert
yoftheToolSt
ri
pMenuIt
em cl
assal
l
owsy
out
ohi
deorshow amenu
i
tem.Letushi
dethePr
ojectMenuonthemenubar
.

CXLI
V
VB.
NET

Addt
hef
oll
owi
ngcodesni
ppett
otheFor
m1_
Loadev
ent
:

Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esMy
Base.
Load
'
Hidet
hepr
ojectmenu
Pr
oject
Tool
Str
ipMenuI
tem1.
Visi
ble=Fal
se '
Sett
hecapt
ionbart
ext
oft
hef
orm.
Me.
Tex
t="
tut
ori
alspoi
nt.
com"EndSub

Addabut
toncont
rol
ont
hef
orm wi
tht
ext'
ShowPr
oject
'.
Addt
hef
oll
owi
ngcodesni
ppett
otheBut
ton1_
Cli
ckev
ent
:

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton1.
Cli
ck
Pr
oject
Tool
Str
ipMenuI
tem1.
Visi
ble=Tr
ueEndSub

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

Cl
i
cki
ngont
heShowPr
ojectbut
tondi
spl
ayst
hepr
ojectmenu:

CXLV
VB.
NET

Di
sabl
eandEnabl
eMenuI
tems
TheEnabledpr
opert
yall
owsyout
odi
sabl
eorgr
ayoutamenui
tem.Letusdi
sabl
ethe
Proj
ectMenuonthemenubar
.
Addt
hef
oll
owi
ngcodesni
ppett
otheFor
m1_
Loadev
ent
:
Pr
ivat
eSubFor
m1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esMy
Base.
Load
'
Disabl
ethepr
ojectmenu
Pr
oject
Tool
Str
ipMenuI
tem1.
Enabl
ed=Fal
se '
Sett
he
capt
ionbart
extoft
hef
orm.
Me.
Tex
t="
tut
ori
alspoi
nt.
com"
EndSub
Addabuttoncontr
ol onthef
orm wi
tht
ext'
Enabl
ePr
oject
'.Addt
hef
oll
owi
ngcodesni
ppett
o
theBut
ton1_Cl
ickevent:

Pr
ivat
eSubBut
ton1_
Cli
ck(
senderAsObj
ect
,eAsEv
ent
Args)_
Handl
esBut
ton1.
Cli
ck
Pr
oject
Tool
Str
ipMenuI
tem1.
Enabl
ed=Tr
ueEndSub

Whentheabovecodeisexecut
edandr unusi
ngStartbut
tonav
ail
abl
eatt
heMi
crosof
t
Vi
sual
Studi
otool
bar,
itwi
l
lshowt hef
oll
owi
ngwindow:

Cl
i
cki
ngont
heEnabl
ePr
ojectbut
tonenabl
est
hepr
ojectmenu:

CXLVI
VB.
NET

SetAccessKey
sforMenuI
tems
Set
ti
ngaccesskey
sforamenual
l
owsausert
osel
ecti
tfr
om t
hekey
boar
dbyusi
ngt
heALT
key
.

Forexampl
e,i
fyouwanttosetanaccesskeyALT+Fforthefi
l
emenu, changeit
sTextwit
h
anadded&( amper
sand)precedi
ngtheaccesskeyl
ett
er.Inotherwords,youchanget
he
textpr
oper
tyoft
hefi
lemenut o&Fi
le.

SetShor
tcutKey
sforMenuI
tems
Whenyousetashortcutkeyforamenui
tem,usercanpresst
heshor
tcutf
rom t
hekey
boar
d
andi
twoul
dr esul
tinoccurr
enceoft
heCl
ickeventofthemenu.

Ashortcutkeyi
ssetforamenui tem usi
ngtheShor
tcut
Key
spropert
y.Forexample,
toseta
short
cutkeyCTRL+E, f
ortheEditmenu:
Selectt
heEditmenuit
em andselecti
tsShor
tcut
Keyspr
oper
tyintheproper
ti
eswindow.

Cl
i
ckt
hedr
opdownbut
tonnextt
oit
.

Sel
ectCt
rlasModi
fi
erandEast
hekey
.

CXLVI
I
VB.
NET

CXLVI
II

You might also like