private void editButtonToolStripMenuItem_Click(object sender, EventArgs e) { // Thanks StackOverflow // Try to cast the sender to a ToolStripItem ToolStripItem menuItem = sender as ToolStripItem; if (menuItem != null) { // Retrieve the ContextMenuStrip that owns this ToolStripItem ContextMenuStrip owner = menuItem.Owner as ContextMenuStrip; if (owner != null) { // Get the control that is displaying this context menu Control sourceControl = owner.SourceControl; // My code int index = flowLayoutPanel1.Controls.IndexOf(sourceControl); MusicButtonInfo ButtonToEdit = CurrentButtons[index]; using (ButtonForm buttonWindow = new ButtonForm(ButtonToEdit.text, ButtonToEdit.textColor.ToArgb(), ButtonToEdit.file, ButtonToEdit.image, ButtonToEdit.background)) { DialogResult result = buttonWindow.ShowDialog(); if (result == DialogResult.OK) { ButtonToEdit.text = buttonWindow.text; ButtonToEdit.textColor = buttonWindow.textColor; ButtonToEdit.file = buttonWindow.file; ButtonToEdit.image = buttonWindow.image; ButtonToEdit.background = buttonWindow.background; ReloadButtons(); } } } } }
public MusicButtonInfoForRemote(MusicButtonInfo mb) { text = mb.text; textColor = ColorTranslator.ToHtml(mb.textColor); image = ""; background = ""; if (mb.image != "") { using (var ms = new MemoryStream()) { Image tempImg = Image.FromFile(mb.image); tempImg.Save(ms, tempImg.RawFormat); image = Convert.ToBase64String(ms.ToArray()); } } if (mb.background != "") { using (var ms = new MemoryStream()) { Image tempBg = Image.FromFile(mb.background); tempBg.Save(ms, tempBg.RawFormat); background = Convert.ToBase64String(ms.ToArray()); } } }
private void addButtonToolStripMenuItem_Click(object sender, EventArgs e) { using (ButtonForm buttonWindow = new ButtonForm()) { DialogResult result = buttonWindow.ShowDialog(); if (result == DialogResult.OK) { MusicButtonInfo buttonToAdd = new MusicButtonInfo(buttonWindow.text, buttonWindow.textColor, buttonWindow.file, buttonWindow.image, buttonWindow.background); CurrentButtons.Add(buttonToAdd); ReloadButtons(); } } }