private PictureBox setEmptyPicture(int posicio) { Logger.Info("Añadiendo elemento vacio en posicion {0}", posicio); PictureBox pic = CreatePicture(posicio); pic.Image = Properties.Resources.no_program; ToolTip tt = new ToolTip(); tt.SetToolTip(pic, $"Posicion {posicio}: Sin programa"); pic.Tag = new { posicio = posicio, commandLine = "", id = 0 }; pic.MouseClick += new MouseEventHandler((s, ev) => { MessageBox.Show("Hola " + (ev.Button == MouseButtons.Left ? "Left" : "Right")); if (ev.Button == MouseButtons.Right) { PictureBox picx = s as PictureBox; dynamic tag = picx.Tag; Logger.Info("Pulsado boton derecho en {0}", tag.posicio); frmPrograma prg = new frmPrograma(configMenu, tag.posicio); Logger.Info("Iniciando dialogo para añadir elemento"); if (prg.ShowDialog() == DialogResult.OK) { Logger.Info("Grabando configuracion"); configMenu.Save(this.fileName); OpcioMenu omx = configMenu.getProgram(tag.posicio); this.setPicture(omx, (int)tag.posicio); // this.Refresh(); // refreshPictures(); } } }); return(pic); }
public bool addProgram(string program, string icon, string label, string pre, string post, int pos, bool execdef) { Logger.Info("addProgram : Add {0}", program); OpcioMenu om = new OpcioMenu(program, icon, label, pre, post, pos, execdef); this.opcions.Add(om); return(true); }
public frmPrograma(ConfigMenu cf, OpcioMenu opc, int posicio, bool edit = true) : this(cf, posicio, true) { this.om = opc; txtPrograma.Text = opc.fileName; txtIcono.Text = opc.fileIcon; txtPre.Text = opc.preExec; txtPost.Text = opc.postExec; cbDefault.Checked = opc.execDefaultPreExec; }
public bool loadProgram(XmlNode prg) { var program = getStringValue(prg, "Executable"); var icon = getStringValue(prg, "Icon"); var label = getStringValue(prg, "Label"); var pre = getStringValue(prg, "PreExec"); var post = getStringValue(prg, "PostExec"); var pos = getIntValue(prg, "Position"); var execdef = getIntValue(prg, "ExecDefault"); OpcioMenu om = new OpcioMenu(program, icon, label, pre, post, pos, execdef == 1 ? true : false); this.AddOpcio(om); return(true); }
public OpcioMenu getProgram(int posicio) { OpcioMenu om = null; if (this.opcions != null) { foreach (OpcioMenu opc in this.opcions) { if (opc.position == posicio) { om = opc; break; } } } return(om); }
public void AddOpcio(OpcioMenu opt) { this.opcions.Add(opt); }
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); }