标签:oid mfile listbox rect files 代码 cte mod get
1. 属性事件列表:
2. 取列表框中被选中的值
ListBox.SelectedValue
3. 动态的添加列表框中的项:
ListBox.Items.Add("所要添加的项");
下面依旧用一个例子来回顾:
代码如下:
using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Windows.Forms; namespace gakki相册2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //存储文件全路径的泛型集合 List<string> list = new List<string>(); //窗体加载的时候初始化listbox private void Form1_Load(object sender, EventArgs e) { string path = Application.StartupPath + @"\gakki"; string[] arrPics = Directory.GetFiles(path); for (int i = 0; i < arrPics.Length; i++) { string picname = Path.GetFileName(arrPics[i]); listBox1.Items.Add(picname); } //把全路径加载到泛型集合里 list.AddRange(arrPics); } private void listBox1_MouseClick(object sender, MouseEventArgs e) { pictureBox1.Image = Image.FromFile(list[listBox1.SelectedIndex]); } } }
代码链接:http://pan.baidu.com/s/1gf5r3Uj 密码:hxme
标签:oid mfile listbox rect files 代码 cte mod get
原文地址:http://www.cnblogs.com/lolitagis/p/7484636.html