Exemplo n.º 1
0
 //当订到界面上时
 private void RemoveButtonToToolTrip(PanelEx panel, DockControlEntity entity)
 {
    this.Items.RemoveByKey(panel.ID);
    SetVisibleState();
 }
Exemplo n.º 2
0
        public bool Add(DockControlEntity entity)
        {

            if (!this.FindForm().IsMdiContainer)
            {
                throw new NotSupportedException("DockControl只支持MID窗体");
            }
            PanelEx panel = new PanelEx();
            panel.ID = Guid.NewGuid().ToString();
            switch (this.Dock)
            {
                case DockStyle.Left:
                    {
                        panel.AllowExtendRight = true;
                        panel.Location = new System.Drawing.Point(this.Location.X + this.Width, this.Location.Y);
                        panel.Size = new System.Drawing.Size(120, this.Height);
                        break;
                    }
                case DockStyle.Right:
                    {
                        panel.AllowExtendLeft = true;
                        panel.Size = new System.Drawing.Size(120, this.Height);
                        panel.Location = new System.Drawing.Point(this.Location.X - panel.Width, this.Location.Y);
                        break;
                    }
                default: throw new NotSupportedException("目前只支持向左和向右停靠");
            }
            if (entity.IsAutoHide)
            {
                panel.Visible = false;
                AddButtonToToolTrip(panel, entity);
            }
            else
            {
                panel.Visible = true;
            }
            this.FindForm().Controls.Add(panel);
            //panel.BeginLoadDate();
            //BackgroundWorker worker = new BackgroundWorker();
            //worker.DoWork += (object sender1111, DoWorkEventArgs e111) =>
            //    {
            AddOneBaseForm frm = entity.DisplayForm;
            // AddOneBaseForm frm=(AddOneBaseForm) Activator.CreateInstance(entity.DisplayForm.GetType());
            frm.IsAutoHide = entity.IsAutoHide;
            frm.ID = panel.ID;
            frm.FrmText = entity.MenuText;
            frm.MdiParent = this.FindForm();
            frm.Parent = panel;
            panel.Controls.Add(frm);
            frm.Dock = DockStyle.Fill;
            frm.Width = panel.Width;
            frm.Show();
            frm.BringToFront();
            PlugInPanel.Add(panel.ID, panel);
            panel.BringToFront();
            if (!entity.IsAutoHide)
            {
                frm.Parent.Dock = this.Dock;
            }
            else
            {
                frm.Parent.Dock = DockStyle.None;
            }

            frm.AddOneAutoHideChanged += (object sender, EventArgs e) =>
            {
                frm.IsAutoHide = !frm.IsAutoHide; //最新的autoHide
                if (!frm.IsAutoHide)
                {
                    frm.Parent.Dock = this.Dock;
                    RemoveButtonToToolTrip(panel, entity);
                }
                else
                {
                    frm.Parent.Dock = DockStyle.None;
                    AddButtonToToolTrip(panel, entity);
                    frm.Parent.Visible = false;
                }
            };
            panel.MouseLeaveExtend(
                () =>
                {
                    if (frm.IsAutoHide)
                    {
                        PlugInPanel[frm.ID].Visible = false;
                    }
                });
            frm.AddOneClosed += (object sender, EventArgs e) =>
            {
                PlugInPanel[frm.ID].Dispose();
                PlugInPanel.Remove(frm.ID);
                RemoveButtonToToolTrip(panel, entity);
                frm.Close();
            };
            //    };
            //worker.RunWorkerCompleted += (object sender ,RunWorkerCompletedEventArgs e) => {
            //};
            //worker.RunWorkerAsync();
            return true;
        }
Exemplo n.º 3
0
 //添加一个按钮(autohide的时候)
 private void AddButtonToToolTrip(PanelEx panel,DockControlEntity entity)
 {
    //  panel.Visible = false;
     ToolStripButton btn = new ToolStripButton();
     btn.Name = panel.ID;
     btn.Text = entity.MenuText;
     btn.Click += (object sender, EventArgs e) =>
     {
         panel.Visible = true;
         panel.BringToFront();
         if (panel.CanFocus)
         {
             panel.Focus();
         }
     };
     this.Items.Add(btn);
     this.Visible = true;
 }