Users who no longer need files/folders have the permission to delete them. This section describes how to implement this function.
Interface Layout
There is a "delete" button in the main interface design, and its (ID) is btndelete. You can click this button to delete an item in directory browsing.
CodeImplementation
On the Design panel, double-click the delete button to add event processing to it.ProgramAs follows:
Private void btndelete_click (Object sender, system. eventargs E)
{
Deletethings (filelistselecteditem. Text );
}
Private void deletethings (string fullpath)
{
If (fullpath. indexof (".") & gt; 0) // delete an object
{
File. Delete (fullpath );
Loaddir (currentpath); // reload the current directory
}
Else // delete a directory
{
Directory. Delete (fullpath );
Loaddir (currentpath); // reload the current directory
}
}
When deleting a file, first determine whether the selected file is a folder or not. If it is a file, the file. Delete () method is called; otherwise, the directory. Delete () method is called. After the deletion is successful, call the loaddir () method to display the changed directory content.