【发布时间】:2017-03-20 23:14:49
【问题描述】:
我正在创建一个将 DLL 加载到 ListBox 中的应用程序。它通过用户按下一个按钮然后用户可以打开文件并将它们加载到列表视图中来做到这一点。
所以它看起来像这样。
通过打开用户文件添加 DLL,然后他们将其添加到自己的列表框中。
我的问题是。当有人在 ListBox 中选择 MaterialSkin.dll 时,如何获取 MaterialSkin.dll 的确切路径并将其放入字符串中?
private void materialFlatButton3_Click_1(object sender, EventArgs e) //button used to load the DLL into the ListBox.
{
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
OpenFileDialog1.Multiselect = true;
OpenFileDialog1.Filter = "DLL Files|*.dll";
OpenFileDialog1.Title = "Select a Dll File";
if (OpenFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// put the selected result in the global variable
fullFileName = new List<String>(OpenFileDialog1.FileNames);
// add just the names to the listbox
foreach (string fileName in fullFileName)
{
listBox2.Items.Add(fileName.Substring(fileName.LastIndexOf(@"\") + 1));
}
}
}
【问题讨论】: