Combo box and List box in VB.Net.ppt

1,634 views 19 slides Sep 08, 2023
Slide 1
Slide 1 of 19
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19

About This Presentation

Combo box and List box in VB.Net


Slide Content

Shri Shivaji Science College, Amravati
Department of Computer Science
Topic-VB.NET
Prepared By
Dr. Ujwala S. Junghare
Assistant Professor
Dept. of Computer Science

Combo box and List box

List Boxes:
•Listboxesdisplayalistofitemsfromwhichtheusercanselectoneormore.Ifthereare
toomanyitemstodisplayatonce,ascrollbarautomaticallyappearstolettheuserscroll
throughthelist.InVisualBasic.NET,eachiteminalistboxisitselfanobject.
•Itallowstheprogrammertoadditemsatdesigntimebyusingthepropertieswindowor
attheruntime.
•YoucancreatealistboxbydraggingaListBoxcontrolfromtheToolboxanddroppingit
ontheform.

You can populate the list box items either from the properties window or at runtime.
Properties of the ListBox Control:
Sr.No
.
Property & Description
1 AllowSelection
GetsavalueindicatingwhethertheListBoxcurrentlyenablesselectionoflistitems.
2 BorderStyle
Getsorsetsthetypeofborderdrawnaroundthelistbox.
3 ColumnWidth
Getsofsetsthewidthofcolumnsinamulticolumnlistbox.
4 HorizontalExtent
Getsorsetsthehorizontalscrollingareaofalistbox.
5 HorizontalScrollBar
Getsorsetsthevalueindicatingwhetherahorizontalscrollbarisdisplayedinthelistbox.

6 ItemHeight
Getsorsetstheheightofaniteminthelistbox.
7 Items
Getstheitemsofthelistbox.
8 MultiColumn
Getsorsetsavalueindicatingwhetherthelistboxsupportsmultiple
columns.
9 ScrollAlwaysVisible
Getsorsetsavalueindicatingwhethertheverticalscrollbarisshown
atalltimes.
10SelectedIndex
Getsorsetsthezero-basedindexofthecurrentlyselectediteminalist
box.
11SelectedIndices
Getsacollectionthatcontainsthezero-basedindexesofallcurrently
selecteditemsinthelistbox.

12 SelectedItem
Getsorsetsthecurrentlyselectediteminthelistbox.
13 SelectedItems
Getsacollectioncontainingthecurrentlyselecteditemsinthelistbox.
14 SelectedValue
GetsorsetsthevalueofthememberpropertyspecifiedbytheValueMemberproperty.
15 SelectionMode
Getsorsetsthemethodinwhichitemsareselectedinthelistbox.Thispropertyhas
values−
•None
•One
•MultiSimple
•MultiExtended
16 Sorted
Getsorsetsavalueindicatingwhethertheitemsinthelistboxaresortedalphabetically.
17 Text
Getsorsearchesforthetextofthecurrentlyselectediteminthelistbox.
18 TopIndex
Getsorsetstheindexofthefirstvisibleitemofalistbox.

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs)
Handles MyBase.Load
' Set the caption bar text of the form.
Me.Text = "tutorialspont.com"
ListBox1.Items.Add("Canada")
ListBox1.Items.Add("USA")
ListBox1.Items.Add("UK")
ListBox1.Items.Add("Japan")
ListBox1.Items.Add("Russia")
ListBox1.Items.Add("China")
ListBox1.Items.Add("India")
End Sub
Private Sub Button1_Click(sender As Object, e As
EventArgs) Handles Button1.Click MsgBox("You have selected
" + ListBox1.SelectedItem.ToString()) End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As
Object, e As EventArgs) Handles
ListBox1.SelectedIndexChanged
Label2.Text = ListBox1.SelectedItem.ToString()
End Sub
End Class

Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As
System.EventArgs) Handles Button1.Click
ListBox1.BeginUpdate()
Dim intLoopIndex As Integer
For intLoopIndex = 1 To 20
ListBox1.Items.Add("Item " &intLoopIndex.ToString())
Next intLoopIndex
ListBox1.EndUpdate()
End Sub

Combo box

The ComboBox control is used to display a drop-down list of various items. It is a
combination of a text box in which the user enters an item and a drop-down list from
which the user selects an item.
Let's create a combo box by dragging a ComboBox control from the Toolbox and
dropping it on the form.
Sr.No. Property & Description
1 AllowSelection
Getsavalueindicatingwhetherthelistenablesselectionoflistitems.
2 AutoCompleteCustomSource
GetsorsetsacustomSystem.Collections.Specialized.StringCollectionto
usewhentheAutoCompleteSourcepropertyissettoCustomSource.
3 AutoCompleteMode
Getsorsetsanoptionthatcontrolshowautomaticcompletionworksfor
theComboBox.
4 AutoCompleteSource
Getsorsetsavaluespecifyingthesourceofcompletestringsusedfor
automaticcompletion.
5 DataBindings
Getsthedatabindingsforthecontrol.

6 DataManager
GetstheCurrencyManagerassociatedwiththiscontrol.
7 DataSource
GetsorsetsthedatasourceforthisComboBox.
8 DropDownHeight
Getsorsetstheheightinpixelsofthedrop-downportionoftheComboBox.
9 DropDownStyle
Getsorsetsavaluespecifyingthestyleofthecombobox.
10 DropDownWidth
Getsorsetsthewidthoftheofthedrop-downportionofacombobox.
11 DroppedDown
Getsorsetsavalueindicatingwhetherthecomboboxisdisplayingitsdrop-downportion.
12 FlatStyle
GetsorsetstheappearanceoftheComboBox.
13 ItemHeight
Getsorsetstheheightofaniteminthecombobox.
14 Items
GetsanobjectrepresentingthecollectionoftheitemscontainedinthisComboBox.

15 MaxDropDownItems
Getsorsetsthemaximumnumberofitemstobedisplayedinthedrop-downpartofthecombobox.
16 MaxLength
Getsorsetsthemaximumnumberofcharactersausercanenterintheeditableareaofthecombobox.
17 SelectedIndex
Getsorsetstheindexspecifyingthecurrentlyselecteditem.
18 SelectedItem
GetsorsetscurrentlyselecteditemintheComboBox.
19 SelectedText
GetsorsetsthetextthatisselectedintheeditableportionofaComboBox.
20 SelectedValue
GetsorsetsthevalueofthememberpropertyspecifiedbytheValueMemberproperty.
21 SelectionLength
Getsorsetsthenumberofcharactersselectedintheeditableportionofthecombobox.
22 SelectionStart
Getsorsetsthestartingindexoftextselectedinthecombobox.
23 Sorted
Getsorsetsavalueindicatingwhethertheitemsinthecomboboxaresorted.
24 Text
Getsorsetsthetextassociatedwiththiscontrol.

PictureBox Control
•ThePictureBoxcontrolisusedfordisplayingimagesontheform.TheImagepropertyof
thecontrolallowsyoutosetanimagebothatdesigntimeoratruntime.
•Let'screateapictureboxbydraggingaPictureBoxcontrolfromtheToolboxanddropping
itontheform.

Sr.No. Property & Description
1 AllowDrop
Specifieswhetherthepictureboxacceptsdatathatauserdragsonit.
2 ErrorImage
Getsorspecifiesanimagetobedisplayedwhenanerroroccursduringtheimage-loadingprocessor
iftheimageloadiscancelled.
3 Image
Getsorsetstheimagethatisdisplayedinthecontrol.
4 ImageLocation
GetsorsetsthepathortheURLfortheimagedisplayedinthecontrol.
5 InitialImage
Getsorsetstheimagedisplayedinthecontrolwhenthemainimageisloaded.
PropertiesofthePictureBoxControl
ThefollowingaresomeofthecommonlyusedpropertiesofthePictureBoxcontrol−

6 SizeMode
Determinesthesizeoftheimagetobedisplayedinthecontrol.Thispropertytakesitsvaluefromthe
PictureBoxSizeModeenumeration,whichhasvalues−
•Normal−theupperleftcorneroftheimageisplacedatupperleftpartofthepicturebox
•StrechImage−allowsstretchingoftheimage
•AutoSize−allowsresizingthepictureboxtothesizeoftheimage
•CenterImage−allowscenteringtheimageinthepicturebox
•Zoom−allowsincreasingordecreasingtheimagesizetomaintainthesizeratio.
7 TabIndex
Getsorsetsthetabindexvalue.
8 TabStop
SpecifieswhethertheuserwillbeabletofocusonthepictureboxbyusingtheTABkey.
9 Text
Getsorsetsthetextforthepicturebox.
10 WaitOnLoad
Specifieswhetherornotanimageisloadedsynchronously.

Sr.
No.
Method Name & Description
1CancelAsync
Cancelsanasynchronousimageload.
2Load
Displaysanimageinthepicturebox
3LoadAsync
Loadsimageasynchronously.
4ToString
Returnsthestringthatrepresentsthecurrentpicturebox.
MethodsofthePictureBoxControl
ThefollowingaresomeofthecommonlyusedmethodsofthePictureBoxcontrol−

PrivateSubButton1_Click(senderAsObject,eAsEventArgs)HandlesButton1.Click
'DimStrAsString="C:\Users\AMITYADAV\Desktop\"
PictureBox1.Image=Image.FromFile("C:\Users\AMITYADAV\Desktop\jtp2.png")
PictureBox1.SizeMode=PictureBoxSizeMode.StretchImage
PictureBox1.Height=250
PictureBox1.Width=400
Label1.Visible=False
EndSub

Timer Control -VB.Net
WhatisTimerControl?
TimerControlplaysanimportantroleintheClientsideprogrammingandServersideprogramming,alsousedinWindowsServices.
ByusingthisTimerControl,windowsallowyoutocontrolwhenactionstakeplacewithouttheinteractionofanotherthread.
UseofTimerControl
WecanuseTimerControlinmanysituationsinourdevelopmentenvironment.Ifyouwanttorunsomecode
afteracertainintervaloftimecontinuously,youcanusetheTimercontrol.Aswellastostartaprocessatafixed
timeschedule,toincreaseordecreasethespeedinananimationgraphicswithtimescheduleetc.youcanusethe
TimerControl.TheVisualStudiotoolboxhasaTimerControlthatallowingyoutodraganddropthetimer
controlsdirectlyontoaWindowsFormsdesigner.Atruntimeitdoesnothaveavisualrepresentationandworks
asacomponentinthebackground.

HowtoTimerControl?
WiththeTimerControl,wecancontrolprogramsinmillisecond,seconds,minutesandevenin
hours.TheTimerControlallowsustosetIntervalpropertyinmilliseconds(1secondisequalto
1000milliseconds).Forexample,ifwewanttosetanintervaloftwominutewesetthevalueat
Intervalpropertyas120000,means120x1000.
TheTimerControlstartsitsfunctioningonlyafteritsEnabledpropertyissettoTrue,bydefault
EnabledpropertyisFalse.
Tags