Implementing a resource-like browser functionality in WinForm requires implementation to drag the files listed in WinForm out into other applications or drag files from other applications into the WinForm application. There are some articles on the web that describe this feature, but they are all quite fragmented and lack a complete example. For this I have written a more complete example of drag-and-drop implementation files, and write this step-by-step explanation if similar functionality is implemented.
Step 1 places a ListView into the WinForm form and initializes the following properties:
listView.View = View.Details;
listView.AllowDrop = true;
Step 2 Compose a list of the functions shown in a directory file listing
/**////<summary>
List files in the folder
</summary>
<param name= "directory" >the directory of the Folder</param>
private void Listfolder (String directory)
{
Labelcurfolder.text = Directory;
string[] filelist = System.IO.Directory.GetFiles (Directory);
ListViewFolder.Items.Clear ();
ListViewFolder.Columns.Clear ();
LISTVIEWFOLDER.COLUMNS.ADD ("Name", 300);
LISTVIEWFOLDER.COLUMNS.ADD ("Size", 100);
LISTVIEWFOLDER.COLUMNS.ADD ("Time", 200);
foreach (String fileName in FileList)
{
Show file name
ListViewItem itemname = new ListViewItem (System.IO.Path.GetFileName (fileName));
Itemname.tag = FileName;
Show file icon
Iconimageprovider Iconimageprovider = new Iconimageprovider (listviewfolder.smallimagelist,
Listviewfolder.largeimagelist);
Itemname.imageindex = Iconimageprovider.geticonimageindex (fileName);
Show file Size
System.IO.FileInfo FileInfo = new System.IO.FileInfo (fileName);
Long size = Fileinfo.length;
String strsize;
if (Size < 1024)
{
Strsize = size. ToString ();
}
else if (Size < 1024 * 1024)
{
Strsize = String.Format ("{0:###.##}kb", (float) size/1024);
}
else if (Size < 1024 * 1024 * 1024)
{
Strsize = String.Format ("{0:###.##}MB", (float) size/(1024 * 1024));
}
Else
{
Strsize = String.Format ("{0:###.##}GB", (float) size/(1024 * 1024 * 1024));
}
Listviewitem.listviewsubitem subitem = new Listviewitem.listviewsubitem ();
Subitem.text = strsize;
Subitem.tag = size;
ITEMNAME.SUBITEMS.ADD (subitem);
Show file time
subitem = new Listviewitem.listviewsubitem ();
DateTime filetime = System.IO.File.GetLastWriteTime (fileName);
Subitem.text = (string) filetime.tolocaltime (). ToString ("Yyyy-mm-dd HH:mm:ss");;
Subitem.tag = FILETIME;
ITEMNAME.SUBITEMS.ADD (subitem);
LISTVIEWFOLDER.ITEMS.ADD (ItemName);
}
}
In the code above, there is a section of the code that shows the icon because it has nothing to do with the drag, I do not post it, interested can download the full code to see.