我正在從.net asp.net移到C#winform。在C#winform上選擇多個文件
我想選擇一個C#WinForm的多個文件,然後顯示在屏幕用戶可以刪除它們所選擇的文件...
其中控制我應該使用顯示在屏幕上的winform的項目?
我正在從.net asp.net移到C#winform。在C#winform上選擇多個文件
我想選擇一個C#WinForm的多個文件,然後顯示在屏幕用戶可以刪除它們所選擇的文件...
其中控制我應該使用顯示在屏幕上的winform的項目?
如果我正確理解你的問題,你應該使用Listbox。用戶可以使用典型的Windows Ctrl/Shift鍵在列表框中輕鬆選擇多個項目,然後單擊要選擇的項目。
下面是自定義控件的屏幕截圖和代碼片段。這應該給你一個創建自己的起點。
/// <summary>
/// Retrieve a list of available files in the input directory
/// </summary>
private void LoadAvaliableFiles()
{
try
{
this.lv_AvailableFiles.Items.Clear();
//Pick up files from structure
//Firstly pick up all files in the target directory
string[] filesFound = this.m_watcher.GetFiles();
// Verify that we have some files to display in the list
if (filesFound != null && filesFound.Length > 0)
{
// The ArrayList will contain PreConversionData objects
foreach (string filePath in filesFound)
{
string fileName = Path.GetFileName(filePath);
//create a list view item for the file
ListViewItem newFile = new ListViewItem(fileName);
newFile.Text = fileName;
newFile.ToolTipText = filePath;
newFile.Tag = filePath;
// Add the new item to the list
this.lv_AvailableFiles.Items.Add(newFile);
}
}
this.lv_AvailableFiles.Refresh();
}
catch (Exception ex)
{
Log.WriteLine(Category.Warning, "Exception detected populating the available files list", ex);
}
}
我的代碼使用文件夾觀察者捕捉任何新添加的文件,但你可以很容易地使用
string [] filesFound = Directory.GetFiles(targetDirectory);
爲什麼這個downvoted? – Tigran 2012-01-11 19:02:51
@Tigran可能是因爲它沒有顯示出什麼研究成果。 (注:我沒有投票) – 2012-01-19 01:28:15
@devn,請改變你的標題,你從ASP.NET中來的事實是不相關的 – 2012-01-19 01:31:13