private void RenameSong(object sender, EventArgs e) { if (this.listViewSongs.SelectedItems.Count > 0) { if (this.listViewSongs.SelectedItems[0].Group != this.listViewSongs.Groups["customMusic"]) { using (RenameMessageBox messageBox = new RenameMessageBox(Path.GetFileNameWithoutExtension(this.listViewSongs.SelectedItems[0].SubItems[1].Text))) { if (messageBox.ShowDialog(this) == DialogResult.OK) { string newName = Path.GetFileNameWithoutExtension(messageBox.NewName) + ".wav"; if (File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", newName))) { ErrorMessageBox.Show(this, "A song already exists with that name.", ""); } else { File.Move( Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", this.listViewSongs.SelectedItems[0].SubItems[1].Text), Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", newName) ); if (File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text))) { File.Move( Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text), Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", newName) ); } this.listViewSongs.SelectedItems[0].SubItems[1].Text = newName; if (this.listViewSongs.SelectedItems[0].ImageIndex == 1) { this.listViewSongs.SelectedItems[0].ImageIndex = 0; this.currentSong.Stop(); this.playing = false; this.playingCustom = false; this.buttonPlay.Text = "Play"; } } } } } } }
public static DialogResult Show(Form parent, string currentName) { using (var form = new RenameMessageBox(currentName)) { return(form.ShowDialog(parent)); } }