Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }