Unit 3 NET
Unit 3 NET
T-I
II
Li
stBox:
TheLi stBoxr epr
esentsaWi ndowscont rolt
odi spl
ayal i
stofi temst oauser.A
usercansel ectanitem from t heli
st.
Properti
es:
I
tems Getst heitemsoft hel i
stbox.
I
temHei ght Getsorset sthehei ghtofani tem i
nt helistbox.
SelectedIndex Get sorset stheindexoft hecurrentlyselecteditem i
nalist
box .
SelectedItem Getst hecur rentl
ysel ect
editemsi nt helistbox.
SelectonMode Get
i sorset sthemet hodi nwhichitemsar eselectedint
he
li
stbox.Thi spr opertyhasv alues:
None
One
Mul t
iSimple
Mul t
iExtended
Sorted Getsorset sav alueindicati
ngwhet hertheitemsi ntheli
st
boxar esor tedalphabet i
call
y.
Mul t
icolumn Getsorset sav alueindicati
ngwhet herthelistboxsupports
mul t
iplecolumns.
ColumnWi dth Get sorset sthewi dthofcol umnsi namul ti
columnl i
stbox.
Ev
ent
s:
Sel
ect
edI
ndexChanged Occur
swhent
heSel
ect
edI
ndexpr
oper
tyofal
i
stboxi
schanged.
Exampl
e:
Publ
i
cCl
assFor
m1
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
Li
stBox1.
It
ems.
Add(
"Apple"
)
Li
stBox1.
It
ems.
Add(
"Orange"
)
Li
stBox1.
It
ems.
Add(
"Mango")
EndSub
Pr
ivat
eSubLi
stBox1_
SelectedIndexChanged(
ByValsenderAsObj
ect
,By
Val
eAs
Sy
stem.Ev
ent
Args)HandlesListBox1.
Select
edVal
ueChanged
Text
Box1.
Text=Li
stBox1.
Sel
ect
edI
tem
EndSub
CheckedLi
stBox:
I
tissimilart
oLi
stbox.I
tsuppor tscheckboxesf oreachi t
em.
Properti
es:
I
tems Getstheitemsoft hel i
stbox.
I
temHei ght Getsorset sthehei ghtofani tem i
nt helistbox.
Select
edIndex Getsorset stheindexoft hecurrentlyselecteditem i
nalist
box.
Select
edItem Getsthecur rentl
ysel ect
editemsi nt helistbox.
Select
ionMode Getsorset sthemet hodinwhi chitemsar eselectedint
he
l
istbox.Thispr opertyhasv alues:
None
One
Multi
Simple
Multi
Extended
Sorted Getsorset sav alueindicati
ngwhet hertheitemsi nthel
ist
boxaresor tedalphabet i
call
y.
Mul
ti
col
umn Get
sorsetsavaluei
ndicati
ngwhet hert
helistboxsuppor
ts
mul
tipl
ecol
umns.
Col
umnWi dth Get
sorsetsthewidt
hofcol umnsinamul t
icolumnli
stbox.
Checkoncl
ick Get
sorsetsav al
uei
ndicati
ngwhet hert
hecheckboxshould
bet
oggledwhenanitem isselect
ed.
Ev
ent
s:
I
temCheck Occur
swhent
hecheckedst
ateofanitem changes.
Sel
ect
edIndexChanged Occur
swhent
heSelect
edI
ndexproper
tyofal i
stboxischanged.
Exampl
e:
Publ
i
cCl
assFor
m1
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
CheckedLi
stBox1.
It
ems.
Add(
"Apple"
)
CheckedLi
stBox1.
It
ems.
Add(
"Orange"
)
CheckedLi
stBox1.
It
ems.
Add(
"Mango")
EndSub
Pr
ivat
eSubCheckedList
Box1_
Sel
ectedI
ndexChanged(ByValsenderAsObj
ect
,By
Val
e
AsSystem.
Event
Args)Handl
esLi
stBox1.
Select
edValueChanged
Text
Box1.
Text=CheckedLi
stBox
1.Sel
ect
edI
tem
EndSub
ComboBox:
Exampl
e:
Publ
i
cCl
assFor
m1
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
ComboBox1.
It
ems.
Add(
"Apple"
)
ComboBox1.
It
ems.
Add(
"Orange"
)
ComboBox1.
It
ems.
Add(
"Mango"
)
EndSub
Pr
ivat
eSubComboBox1_Sel
ectedIndexChanged(ByVal
senderAsObj
ect
,By
Val
eAs
Sy
stem.Ev
ent
Args)Handl
esListBox1.Sel
ectedVal
ueChanged
Text
Box1.
Text=ComboBox1.
Sel
ect
edI
tem
EndSub
EndClass
Li
nkedLabel
:
Li
nkLabelCont
roli
sanext
ensi
onofLabelcont
rolt
o di
spl
ayoneormor
e
hy
per
li
nks.
Pr
operties:
Di
sabledLinkCol
or Getsorset
sthecol
orusedwhendi
spl
ayi
ngadi
sabl
ed
l
ink.
Li
nkcolor Getsorset
sthecol
orusedwhendi
spl
ayi
nganor
malli
nk.
Li
nkarea Get
sorsetstherangeinthetexttotr
eatasali
nk.
Li
nkvi
sit
ed Get
/Setaval
ueindicat
ingthatli
nkisvi
sit
edornot
.
Vi
sit
edli
nkcol
or Det
erminest
hecolorofthehy per
li
nkwhenli
nkvi
sit
ed
pr
opert
yissettotr
ue.
Ev
ent
s:
Li
nkCl
i
cked Occur
swhenal
i
nki
scl
i
ckedwi
thi
nthecont
rol
.
Exampl
e:
Publ
i
cCl
assFor
m1
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
Li
nkLabel
1.Text="
Cli
ckher
etogetmor
einf
o."
EndSub
Pr
ivat
eSubLinkLabel1_LinkCli
cked(
By ValsenderAsSystem.
Object
,By
Val
eAs
Syst
em.Windows.
For ms.LinkLabel
LinkCli
ckedEvent
Args)Handl
es
Li
nkLabel
1.Li
nkCl
icked
Sy
stem.
Diagnost
ics.
Process.
Star
t((
"ht
tp:
//www.
micr
osof
t. )
com"
EndSub
EndClass
Pi
ctur
eBox:
ThePi ctur
eBoxcont rolisusedf ordispl
ayi
ngi magesont hef orm.TheI mage
propertyofthecontr
olal l
owsy outosetani magebot hatdesi gnt i
meandatr un
ti
me.
Properti
es:
I
mage Get sorsetstheimagethatisdisplayedbyPi ctureBox.
I
mageLocat ion Get sorsetsthepathorURLf ortheimaget odi splayinthe
PictureBox.
I
nitial
Image Get sorsetstheimagedisplayedinthePictureBoxcont rol
whent hemainimageisloading.
ErrorI
mage Get sorsetstheimagetodisplaywhenaner roroccur s
duringt hei
mage-loadi
ngprocessori ftheimagel oadis
canceled.
Si
zeMode Indicateshowtheimagei sdi
splay
ed.Fi
veopti
ons:Nor
mal
,
Stretchimage,
Autosize,
Center
Image,Zoom
Wai
tOnLoad Get sorsetsaval
uei ndi
cati
ngthatpr
ocessi
ngwill
stop
untilanimageisloaded.
Exampl
e:
Publ
icCl
assFor
m1
Pr
ivat
eSubForm1_
Load(
senderAsObj
ect
,eAsEv
ent
Args)Handl
es
MyBase.
Load
Pi
ctur
eBox1.
Image=I
mage.
FromFi
l
e(“
C:\
User
s\MyPi
ctur
es\
Logo.
jpg”
)
EndSub
EndCl
ass
Ti
mer
:
Timeriscomponentthatcauseper
iodi
cti
ckev
entt
haty
oucanuset
oexecut
e
codeatspeci
fi
cint
erv
als.
Proper
ti
es:
Enabl
ed Getsorset
swhetherthet
imeri srunni
ng.
I
nterv
al Getsorset
stheti
me, i
nmill
iseconds,beforet
he(Ti
ck
eventi
srai
sedrel
ati
vetothelastoccurrenceoft
he(Ti
ck
event.
Ev
ents:
Ti
ck Occur
swhent hespeci
fi
edt
imeri
nter
valhasel
apsedand
t
hetimeri
senabled.
Met
hods:
St
art Ti
merwi
l
lst
artt
icki
ng
St
op Ti
merwi
l
lst
opt
icki
ng
Exampl
e:
Publ
i
cCl
assFor
m1
Di
m secondAsI
nteger
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
Ti
mer
1.I
nter
val=1000
Ti
mer
1.St
art
()
EndSub
Pr
ivat
eSubTi
mer1_Tick(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esTi
mer1.
Tick
Label
1.Text=Dat
eTi
me.
Now.
ToSt
ri
ng
second=second+1
Ifsecond>=10Then
Ti
mer
1.St
op(
)
EndI
f
EndSub
EndCl
ass
Pr
ogr
essBar
:
Pr
ogressbardispl
aysrectanglei nahor i
zont albart ol ettheuserwat chthe
pr
ogressofsomeoperat
ions.
Pr
operti
es:
St
ep Getsorsetstheamountbywhi chacal ltothe
(Perf
ormStepmet hodincreasest hecur r
ent
posit
ionofthepr ogressbar.
MarqueeAni
mati
onSpeed Get sorsetsthet imeper i
od, i
nmi ll
iseconds,thati
t
takestheprogressbl ocktoscr ol
lacr ossthe
progressbar.
Maximum Getsorsetsthemaxi mum v alueoft herangeof
thecontrol
.
Mi
nimum Getsorsetsthemi ni
mum val
ueoftherangeoft
he
control
.
St
yle Getsorsetsthemannerinwhichprogr
essshoul
d
beindicat
edont heprogr
essbar
.Threeopti
ons:
Blocks,Cont
inuousandMarquee.
Methods:
Per
formStep The Per f
ormStep method i
ncr
ement sthe v
alue ofthe
progress bar by the amount speci
fi
ed by the (
Step
property
.
Exampl
e:
Publ
i
cCl
assFor
m1
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
Pr
ogr
essBar
1.MarqueeAnimati
onSpeed=100
Pr
ogr
essBar
1.Step=100
Pr
ogr
essBar
1.Perf
ormStep()
EndSub
Endcl
ass
Dat
eTi
mePi
cker
:
Ev
ent
s:
For
mat
Changed Occur
swhent
heFor
matpr
oper
tyv
aluehaschanged.
Exampl
e:
Publ
i
cCl
assFor
m1
Pri
vat
eSubBut ton1_Cli
ck(
senderAsObj ect
,eAsEvent
Args)Handl
esBut
ton1.
Cli
ck
Di
m d1AsDat eTi
me=Dat eTimePicker1.
Val
ue
Di
m d2AsDat eTi
me=Dat eTimePicker2.
Val
ue
DimresultAsTi meSpan=d2. Subtract
(d1)
Di
m daysAsI nteger=result
.Tot
alDay s
Label
1.Text=day s
EndSub
Endcl
ass
Scr
oll
Bar
s:
TheScr ollBarcontr
olsdi splayv ert
icalandhor i
zontalscrollbarsontheform.
Thisisusedf ornavigat
ingt hroughl argeamountofi nf
ormat i
on.Ther
earetwo
typesofscr ol
lbarcontr
ols:HScr oll
Barf orhor
izontalscr
ollbarsandVScroll
Bar
forvert
icalscr
ollbar
s.
Propert
ies:
LargeChange Getsorset sav al
uetobeaddedt oorsubt r
actedf
rom
t
heVal uepr opert
ywhent hescrol
l boxismoveda
l
argedi stance.
Smal
l
Change etsorset sthevaluet
obeaddedt oorsubt r
actedfrom
theVal ueproper
tywhent hescr ol
lboxi smov eda
smal ldist
ance.
Maxi
mum Getsorset stheupperli
mi tofvaluesoft hescrol
lable
range.
Mi
nimum Getsorset sthelowerli
mitofv aluesoft hescrol
lable
range.
Val
ue Getsorset sanumer i
cv al
uet hatrepresentsthe
currentpositi
onofthescrollboxont hescr ol
lbar
control.
Event
s:
Scrol
l Occur
swhent
hecont
rol
ismov
ed.
Val
ueChanged Occur
s when the Val
ue proper
ty changes,ei
ther by
handl
i
ngtheScr
oll
eventorpr
ogrammatical
ly
.
Exampl
e:
Publ
i
cCl
assFor
m1
Pri
vat
eSubFor m2_Load(
ByValsenderAsSy
stem.
Obj
ect
,By
Val
eAs
Sy
stem.EventArgs)Handl
esMy Base.
Load
VScroll
Bar1.Lar
geChange=20
VScroll
Bar1.Small
Change=5
VScroll
Bar1.Val
ue=10
EndSub
Endcl
ass
Ri
chTextBox:
RichTextboxisusedfordispl
ayi
ng,enter
ing,andmani
pul
ati
ngr
icht
extwi
th
format
ti
ng.Itcandi
spl
ayfont
s,col
ors,
li
nksetc.
Proper
ti
es:
Sel
ect
edText GetorSettheselectedtextwi thi
nt hecontrol
.
Sel
ect
ionColor GetorSetcolorfortheselectedt ext
Sel
ect
ionFont Getorsett
hef ontforthesel ectedt ext
.
Sel
ect
ionBull
et Getsorsetsav alueindi
catingwhet herthebul
letst
ylei
s
appli
edt othecurrentselecti
on.
Bul
l
eti
ndent Getsorset stheindentati
onusedi ntheRichTextBox
controlwhent hebull
etstyleisappli
edt ot
het ext.
Det
ect
Url
s Getsorset sav al
ueindicati
ngwhet herornott he
RichTextBoxwi l
lautomat i
cal
lyformataUniform Resource
Locator(URL)wheni ti
stypedintothecontrol.
Zoomf
act
or Getsorset sthecurrentzoom leveloftheRichTextBox.
Events:
TextChanged Occur
swhent
he(
Textpr
oper
tyv
aluechanges.
Exampl
e:
Publ
i
cCl
assFor
m1
Pri
vat
eSubForm2_Load(
ByValsenderAsSy
stem.
Obj
ect
,By
Val
eAs
Sy
stem.Ev
ent
Args)Handl
esMy Base.
Load
Pri
vat
eSubButton1_
Click(
By Val
senderAsSy
stem.
Obj
ect
,By
Val
eAs
Sy
stem.Ev
ent
Args)HandlesButton1.
Cli
ck
Ri
chText
Box1.
Sel
ect
All(
)
Ri
chText
Box1.
Sel
ect
ionFont=NewFont(
RichText
Box1.
Font
,Font
Sty
le.
Bol
d)
Ri
chText
Box1.
Sel
ect
ionColor=Col
or.
Red
Ri
chText
Box1.
Bul
let
Indent=10
Ri
chText
Box1.
Sel
ecti
onBull
et=Tr
ue
EndSub
EndCl
ass
MaskedTextBox:
I
tusesamaskt
odi
sti
ngui
shbet
weenpr
operandi
mpr
operuseri
nput
.
Pr
opert
ies:
Mask Getsorset
stheinputmaskt ouseatrunti
me.
Pr
omptChar Getsorset
sthecharacterusedtor
epresentt
he
absenceofuseri
nputinMaskedTextBox.
BeepOnEr
ror Getsorsetsav al
uei ndi
cati
ngwhet herthemaskedt ext
boxcontrolraisesthesy st
em beepf oreachuserkey
str
okethatitrejects.
Al
lowPrompt AsI
nput Getsorsetsav al
uei ndi
cati
ngwhet her(PromptChar
canbeent eredasv aliddatabytheuser.
HidePr
ompt OnLeave Getsorsetsav al
uei ndi
cati
ngwhet hertheprompt
charact
ersint heinputmaskar ehiddenwhent he
maskedt extboxl osesfocus.
Passwordchar Getsorsetst hechar act
ertobedisplayedinsubsti
tute
foruseri
nput .
Ev
ents:
MaskChanged Occur
saf
tert
hei
nputmaski
schanged.
MaskI
nput
Changed Occur
swhentheuser'
sinputorassi
gnedchar
acterdoes
notmatch t
he cor
respondi
ng formatelementoft he
i
nputmask
Exampl
e:
Publ
i
cCl
assFor
m1
Pr
ivat
eSubForm1_Load(
ByVal
senderAsSy
stem.
Obj
ect
,By
Val
eAsSy
stem.
Event
Args)
Handl
esMyBase.
Load
MaskedText
Box1.
Mask="
0000000"
EndSub
Di
ff
erencebet
weenCheckboxandRadi
oBut
ton
CheckBox Radi
oBut
ton
In Check box,y ou can sel ect I
nRadiobut
ton,
youcansel
ectone
multi
pleopti
ons. opt
ionatat
ime.
Checkboxesar esquare. Radiobuttonsar ecircular.
Wheny oucli
ckt hecheckbox, l
it
tl
e Wheny oucl i
ckonar adi
obutton,a
checkmarkappear sinthemi ddl
e l
itt
ledotappear si nthemi ddl
eof
ofthesquare. thecir
cle.
Wheny oucli
ckt heanothercheck I
fy oucli
ckadi fferentchoice,t
he
box,t
hecheckmar koffir
stcheck dotwillmov etot hecent r
eoft he
boxdoesn'tchange. newcirclethatyouhav eselect
ed
i
nt heradiobutton
Di
ff
erencebet
weenLi
stboxandComboBox
Li
stBox ComboBox
Ali
stboxisar
ectangul
arbox Acomboboxi sacombi nati
onofa
whereit
emscanbel i
sted. drop-down- l
i
stwithasingle-
line
textbox.
Wecansel ectmult
ipl
eoptionfr
om Wecansel ectonlyoneoptionfrom
l
ist. l
ist.
Wecanusecheckboxwi t
hin Wecan' tusecheckboxwi thin
l
istbox. combobox.
ListboxOccupiesmor espaceon I
tOccupi eslessspaceont hef orm
thef or
m butshowsmor ethanone butshowsonl yonevaluefor
value. visi
bil
it
y.
Itdoesnotcont ai
ntextboxto I
tcont ai
nst extboxtowr i
teani tem.
wr i
teanitem.
Cr
eat
ingMenus
Menusarethosecontr
olst
hatall
owt heusertomakeselecti
onsandalsohideaway
t
hoseselect
ionswhentheyarenotneeded.
I
nvb.net
,theMenuStri
pcontr
olisusedtocreatemenuont heform.Iti
scontai
nerf
or
t
heMenuI t
em obj
ects.
MenusaremadeupofMenuI tem obj
ectsthatrepr
esentt
heindiv
idualpar
tsofmenu.
Toaddmenust
oyourMDIpar
entf
orm
Doubl
e-cl
i
ckt
heMenuSt
ri
ptool
int
heTool
boxwi
ndowt
oaddanewobj
ectnamed
Mai
nMenu1t
othef
ormt
ray
.
Att
het
opoft
heMDIpar
entf
orm,
cli
ckt
heboxwi
thTy
peHer
eini
tandt
ype&Fi
l
e.
Pr
essEnt
ert
omov
etot
henextmenui
tem andt
ype&New.
Pr
essEnt
ert
omov
etot
henextmenui
tem andt
ypeahy
phen(
-)
.
Pr
essEnt
erandt
ypeE&xi
t.
Youhavenowcreatedt
hefi
rstdr
op-downmenuony
ourmai
nfor
m.Youshoul
dhav
e
somethi
ngthatl
ooksli
keFi
gure2.
Todi
spl
ayacheckmar
knextt
omenui
tem,
sett
heCheckedPr
oper
tyTRUE.
Shor
tCutKey
Youcanusetheshor t
cutpr
opertytodefi
neakeyboardcombinat
iont
hatcanbe
pressedt
oselectthemenuitem,settheShowShor
tcutproper
tyt
oTRUEt odi
spl
ayt
hat
keycombinat
ioninthemenui t
em’scapti
on.
Separ
ator
Set
ti
ngt
heTextpr
oper
tyt
oahy
phen(
-)conv
ert
sthemenui
tem i
ntoamenusepar
ator
.
AccessKey
Pref
acingacharact
erinamenui tem’
scapti
onwit
hanampersand(&)under
li
nesthat
char
acterandmakesitintoanaccesskey
,whichmeanst
heusercansel
ectthati
tem
bypressi
ngAltandthatcharact
er.
Ex,
giv
ingamenui
tem t
hecapt
ion“
&Exi
t”makesEi
ntoaccesskeyf
ort
hismenui
tem.
Cr
eat
ingShor
tCutMenus(
Pop-
UpMenu)
Doubl
e-cl
i
ckt heCont
extMenuSt
ri
ptool
int
heTool
boxwi
ndowt
oaddanewobj
ect
namedMai nMenu1tothefor
mtray.
Cl
i
ckt
heboxwi
thTy
peHer
eini
tandt
ypeRef
resh.
Pr
essEnt
ert
omov
etot
henextmenui
tem andt
ype&New.
ThensetCont
extMenuStr
ipproper
tyoft
hecont
rolt
oNameoftheCont
ext
Menust
ri
p
cont
rol
.Henceri
ghtcl
ickontheconrol
,I
tshowspopupmenu.