private void removeImg_Click(object sender, EventArgs e) { selected_button = ((sender as MenuItem).Parent as ContextMenu).SourceControl as SoundButton; if (selected_button == null) { return; } selected_button.imagePath = null; selected_button.setImage(null); updateDataFile(); }
private void editImgBtn_Click(object sender, EventArgs e) { selected_button = (((sender as MenuItem).Parent as MenuItem).Parent as ContextMenu).SourceControl as SoundButton; if (selected_button == null) { return; } string imagePath; OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "Image files(*.png;*.jpg;*.jpeg)|*.png;*.jpg;*.jpeg"; // Just common types ¯\_(ツ)_/¯ if (fileDialog.ShowDialog() == DialogResult.OK) { imagePath = fileDialog.FileName; } else { imagePath = null; // I.E Click cancel to remove image } fileDialog.Dispose(); selected_button.imagePath = imagePath; selected_button.setImage(imagePath); updateDataFile(); }