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.
Code Implementation
On the Design panel, double-click the delete button to add an event handler for it as follows:
Copy codeThe Code is as follows:
Private void BtnDelete_Click (object sender, System. EventArgs e)
{
DeleteThings (FileList. SelectedItem. Text );
}
Private void DeleteThings (string FullPath)
{
If (FullPath. IndexOf (".")> 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.