Ejemplo n.º 1
0
        public void AddButton(int horPosition, int verPosition, string name, string path, Image img)
        {
            ButtonPanel bp = new ButtonPanel(sizeWidth, sizeHeight, path, name, img, this);

            bp.Tag = name;
            int x = blankSeperator + (horPosition - 1) * (bp.Width + elementSeperator);
            int y = blankSeperator + (verPosition - 1) * (bp.Height + elementSeperator);

            bp.Location = new Point(x, y);
            this.Controls.Add(bp);
            bp.OnDelEvent   += new ButtonPanel.DelDelegate(bp_OnDelEvent);
            bp.OnClickEvent += new ButtonPanel.ClickDelegate(bp_OnClickEvent);
        }
Ejemplo n.º 2
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            string fileName = string.Empty;
            string name     = string.Empty;
            bool   isMove   = false;

            if (drgevent.Data.GetFormats()[0] == "VirtualDesktop.ButtonPanel")
            {
                ButtonPanel bp = (ButtonPanel)drgevent.Data.GetData(typeof(ButtonPanel));
                fileName = bp.path;
                name     = bp.Tag.ToString();
                isMove   = true;
            }
            else
            {
                fileName = ((System.Array)drgevent.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            }

            if (string.IsNullOrEmpty(fileName) || (!File.Exists(fileName) && !Directory.Exists(fileName)))
            {
                return;
            }

            if (!isMove)
            {
                name = Path.GetFileNameWithoutExtension(fileName);
                FormRename fr = new FormRename(fileName, name);
                if (DialogResult.OK == fr.ShowDialog())
                {
                    Image img = GetFileImage(fileName);
                    Point p   = this.PointToClient(new Point(drgevent.X, drgevent.Y));
                    name = fr.name;
                    AddButtonByLocation(p.X, p.Y, name, fileName, img);
                }
                else
                {
                    return;
                }
            }
            else
            {
                Image img = GetFileImage(fileName);
                Point p   = this.PointToClient(new Point(drgevent.X, drgevent.Y));
                bp_OnDelEvent(name);
                AddButtonByLocation(p.X, p.Y, name, fileName, img);
            }
        }
Ejemplo n.º 3
0
        private void bp_OnDelEvent(string name)
        {
            ButtonPanel con = null;

            foreach (Control control in this.Controls)
            {
                if (control is ButtonPanel && (control as ButtonPanel).Tag.ToString() == name)
                {
                    con = control as ButtonPanel;
                    break;
                }
            }
            if (con != null)
            {
                con.OnDelEvent -= new ButtonPanel.DelDelegate(bp_OnDelEvent);
                this.Controls.Remove(con);
                DeleElement(con.Tag.ToString());
            }
        }