private void btnOK_Click(object sender, EventArgs e) { if (txtPrograma.Text == "") { MessageBox.Show("Nom de fitxer buit"); txtPrograma.Focus(); return; } if (this.edit) { cf.RemoveOpcio(om.dynId); } cf.addProgram(txtPrograma.Text, txtIcono.Text, txtLabel.Text, txtPre.Text, txtPost.Text, int.Parse(lblPosition.Text), cbDefault.Checked); DialogResult = DialogResult.OK; Close(); }
private PictureBox setPicture(OpcioMenu om, int posicio) { Logger.Info("AƱadiendo elemento en posicion {0}", posicio); PictureBox pic = CreatePicture(posicio); ToolTip tt = new ToolTip(); if (om.fileIcon == null || !File.Exists(om.fileIcon)) { pic.Image = Properties.Resources.programDefault; } else { pic.Image = Image.FromFile(om.fileIcon); } if (om.label == null) { tt.SetToolTip(pic, $"Executable: {om.fileName}"); } else { tt.SetToolTip(pic, om.label); } pic.Tag = new { posicio = posicio, commandLine = om.fileName, id = om.dynId }; pic.MouseClick += new MouseEventHandler((s, ev) => { PictureBox picx = s as PictureBox; dynamic tag = picx.Tag; OpcioMenu omx = configMenu.getProgram(tag.posicio); if (ev.Button == MouseButtons.Left) { System.Diagnostics.Process.Start(tag.commandLine); } if (ev.Button == MouseButtons.Right && Control.ModifierKeys == Keys.None) { frmPrograma prg = new frmPrograma(configMenu, omx, tag.posicio); if (prg.ShowDialog() == DialogResult.OK) { configMenu.Save(this.fileName); picx.Hide(); omx = configMenu.getProgram(tag.posicio); PictureBox picNew = this.setPicture(omx, (int)tag.posicio); this.Controls.Add(picNew); } } if (ev.Button == MouseButtons.Right && (ModifierKeys & Keys.Control) == Keys.Control && (Keys.Alt & Control.ModifierKeys) != Keys.Alt ) { DialogResult delete = MessageBox.Show("Borrar programa", "Borrar", MessageBoxButtons.OKCancel); if (delete == DialogResult.OK) { configMenu.RemoveOpcio((Guid)tag.id); configMenu.Save(this.fileName); picx.Hide(); PictureBox picNew = setEmptyPicture(tag.posicio); this.Controls.Add(picNew); } } }); pic.Show(); return(pic); }