1. List of attribute events:
- The selection type of the entries in the SelectionMode component, that is, multiple selection (multiple), single
- The Rows list box shows the total number of rows
- Selected detect if the entry is selected
- The type returned by SelectedItem is ListItem, which gets the selected entry in the list box
- Total number of entries in the Count list box
- SelectedIndex the index value of the selected item in the list box
- Items refers to all items in a list box, and the type of each item is ListItem
- SelectedIndexChanged triggering an event when the selection changes
2. Take the selected value from the list box
Listbox.selectedvalue
3. Add the items in the list box dynamically:
LISTBOX.ITEMS.ADD ("Items to be added");
The following is still an example to review:
The code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.Drawing;usingSystem.IO;usingSystem.Windows.Forms;namespaceGakki album 2{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } //a generic collection that stores the full path of a filelist<string> list =Newlist<string>(); //Initialize the listbox when the form is loaded Private voidForm1_Load (Objectsender, EventArgs e) { stringPath = Application.startuppath +@"\gakki"; string[] Arrpics =directory.getfiles (path); for(inti =0; i < arrpics.length; i++) { stringPicname =Path.getfilename (Arrpics[i]); LISTBOX1.ITEMS.ADD (Picname); } //load the full path into the generic collectionlist. AddRange (Arrpics); } Private voidListbox1_mouseclick (Objectsender, MouseEventArgs e) {pictureBox1.Image=Image.FromFile (List[listbox1.selectedindex]); } }}
Code Link: http://pan.baidu.com/s/1gf5r3Uj Password: hxme
WinForm Review [3] ListBox control