listbox
DESCRIPTION
ListBox. 1. Предназначение. Списъчната кутия служи да представи информация във вид на списък; Възможности: Избор на едни или повече елемента; Добавяне и премахване на елемент; Сортиране на списък; Преброяване на елементите и др. 2. Местоположение в инструменталната кутия. 3. Свойства. - PowerPoint PPT PresentationTRANSCRIPT
1. Предназначение
Списъчната кутия служи да представи информация във вид на списък;
Възможности:Избор на едни или повече елемента;Добавяне и премахване на елемент;Сортиране на списък;Преброяване на елементите и др.
2. Местоположение в инструменталната кутия
3. СвойстваProperty Description
AllowSelectionGets a value indicating whether the ListBox currently enables selection of list items.
BorderStyleGets or sets the type of border drawn around the list box.
ColumnWidthGets of sets the width of columns in a multicolumn list box.
HorizontalExtentGets or sets the horizontal scrolling area of a list box.
HorizontalScrollBarGets or sets the value indicating whether a horizontal scrollbar is displayed in the list box.
ItemHeight Gets or sets the height of an item in the list box.
Items Gets the items of the list box.
MultiColumnGets or sets a value indicating whether the list box supports multiple columns.
ScrollAlwaysVisibleGets or sets a value indicating whether the vertical scroll bar is shown at all times.
SelectedIndexGets or sets the zero-based index of the currently selected item in a list box.
SelectedIndicesGets a collection that contains the zero-based indexes of all currently selected items in the list box.
SelectedItem Gets or sets the currently selected item in the list box.
SelectedItemsGets a collection containing the currently selected items in the list box.
SelectedValueGets or sets the value of the member property specified by the ValueMember property.
SelectionMode
•Gets or sets the method in which items are selected in the list box. This property has values:None•One•MultiSimple•MultiExtended
SortedGets or sets a value indicating whether the items in the list box are sorted alphabetically.
TextGets or searches for the text of the currently selected item in the list box.
TopIndexGets or sets the index of the first visible item of a list box.
4. МетодиMethod Name Description
BeginUpdatePrevents the control from drawing until the EndUpdate method is called, while items are added to the ListBox one at a time.
ClearSelected Unselects all items in the ListBox.
EndUpdateResumes drawing of a list box after it was turned off by the BeginUpdate method.
FindString Finds the first item in the ListBox that starts with the string specified as an argument.
FindStringExactFinds the first item in the ListBox that exactly matches the specified string.
GetSelectedReturns a value indicating whether the specified item is selected.
SetSelectedSelects or clears the selection for the specified item in a ListBox.
OnSelectedIndexChanged Raises the SelectedIndexChanged event.
OnSelectedValueChanged Raises the SelectedValueChanged event.
5. Практическа задача 1• Създайте следния потребителки
интерфейс.
• Кодирайте формата, списъчната кутия и бутона по следния начин:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
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
6. Практическа задача 2• Създайте следния потребителки
интерфейс.
• Кодирайте формата и бутон 1 по следния начин:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListBox1.MultiColumn = True
ListBox1.SelectionMode = SelectionMode.MultiExtended
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) _ Handles Button1.Click
ListBox1.Items.Add("Safety")
ListBox1.Items.Add("Security")
ListBox1.Items.Add("Governance")
ListBox1.Items.Add("Good Music")
ListBox1.Items.Add("Good Movies")
ListBox1.Items.Add("Good Books")
ListBox1.Items.Add("Education")
ListBox1.Items.Add("Roads")
ListBox1.Items.Add("Health")
ListBox1.Items.Add("Food for all")
ListBox1.Items.Add("Shelter for all")
ListBox1.Items.Add("Industrialisation")
End Sub
• Кодирайте бутоните по следния начин:
Private Sub Button2_Click(sender As Object, e As EventArgs) _ Handles Button2.Click
ListBox1.Sorted = True
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) _ Handles Button3.Click
ListBox1.Items.Clear()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) _ Handles Button4.Click
ListBox1.Items.Remove(ListBox1.SelectedItem.ToString)
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) _ Handles Button5.Click
Label1.Text = ListBox1.Items.Count
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) _ Handles ListBox1.SelectedIndexChanged
Label3.Text = ListBox1.SelectedItem.ToString()
End Sub