Exemplo n.º 1
0
        public override void PerformRestore(DockingManager dm)
        {
            int count = dm.Container.Controls.Count;

            int min = -1;
            int max = count;

            if (dm.InnerControl != null)
                min = dm.Container.Controls.IndexOf(dm.InnerControl);

            if (dm.OuterControl != null)
                max = dm.OuterControlIndex();

            int beforeIndex = -1;
            int afterIndex = max;
            int beforeAllIndex = -1;
            int afterAllIndex = max;

            // Create a collection of the Zones in the appropriate direction
            for(int index=0; index<count; index++)
            {
                Zone z = dm.Container.Controls[index] as Zone;

                if (z != null)
                {
                    StringCollection sc = ZoneHelper.ContentNames(z);

                    if (_state == z.State)
                    {
                        if (sc.Contains(_best))
                        {
                            // Can we delegate to a child Restore object
                            if (_child != null)
                                _child.PerformRestore(z);
                            else
                            {
                                // Just add an appropriate Window to start of the Zone
                                dm.AddContentToZone(_content, z, 0);
                            }
                            return;
                        }

                        // If the WindowContent contains a Content previous to the target
                        if (sc.Contains(_previous))
                        {
                            if (index > beforeIndex)
                                beforeIndex = index;
                        }

                        // If the WindowContent contains a Content next to the target
                        if (sc.Contains(_next))
                        {
                            if (index < afterIndex)
                                afterIndex = index;
                        }
                    }
                    else
                    {
                        // If the WindowContent contains a Content previous to the target
                        if (sc.Contains(_previousAll))
                        {
                            if (index > beforeAllIndex)
                                beforeAllIndex = index;
                        }

                        // If the WindowContent contains a Content next to the target
                        if (sc.Contains(_nextAll))
                        {
                            if (index < afterAllIndex)
                                afterAllIndex = index;
                        }
                    }
                }
            }

            dm.Container.SuspendLayout();

            // Create a new Zone with correct State
            Zone newZ = dm.CreateZoneForContent(_state);

            // Restore the correct content size/location values
            _content.DisplaySize = _size;
            _content.DisplayLocation = _location;

            // Add an appropriate Window to start of the Zone
            dm.AddContentToZone(_content, newZ, 0);

            // Did we find a valid 'before' Zone?
            if (beforeIndex != -1)
            {
                // Try and place more accurately according to other edge Zones
                if (beforeAllIndex > beforeIndex)
                    beforeIndex = beforeAllIndex;

                // Check against limits
                if (beforeIndex >= max)
                    beforeIndex = max - 1;

                dm.Container.Controls.SetChildIndex(newZ, beforeIndex + 1);
            }
            else
            {
                // Try and place more accurately according to other edge Zones
                if (afterAllIndex < afterIndex)
                    afterIndex = afterAllIndex;

                // Check against limits
                if (afterIndex <= min)
                    afterIndex = min + 1;

                if (afterIndex > min)
                    dm.Container.Controls.SetChildIndex(newZ, afterIndex);
                else
                {
                    // Set the Zone to be the least important of our Zones
                    dm.ReorderZoneToInnerMost(newZ);
                }
            }

            dm.Container.ResumeLayout();
        }
        /// <summary>
        /// 为设计器添加可停靠窗口
        /// </summary>
        private void AddDockingManagers()
        {
            dockManager = new DockingManager(this, VisualStyle.IDE);
            //定义对象OuterControl,Docking Manager不会关注该对象以后生成的对象的窗口区域
            //对象InnerControl,Docking Manager不会关注在该对象生成以前的对象的窗口区域
            dockManager.OuterControl = this.toolStripOperation;
            dockManager.InnerControl = this.ViewDesign;

            //添加可隐藏的控件模块库窗口
            this.tabSolution_Controls = new Content(this.dockManager);
            this.tabSolution_Controls.Control = this.toolboxServiceImpl;
            this.tabSolution_Controls.FullTitle = "控制模块库";
            this.tabSolution_Controls.Title = "控制模块库";
            this.tabSolution_Controls.AutoHideSize = this.toolboxServiceImpl.Size;
            this.tabSolution_Controls.DisplaySize = this.toolboxServiceImpl.Size;
            dockManager.Contents.Add(this.tabSolution_Controls);
            dockManager.AddContentWithState(this.tabSolution_Controls, State.DockLeft);

            //添加可隐藏的属性设计窗口
            this.tabSolution_Property = new Content(this.dockManager);
            this.tabSolution_Property.Control = this.controlfilteredPropertyGrid;
            this.tabSolution_Property.FullTitle = "模块属性";
            this.tabSolution_Property.Title = "模块属性";
            this.tabSolution_Property.AutoHideSize = this.controlfilteredPropertyGrid.Size;
            this.tabSolution_Property.DisplaySize = this.controlfilteredPropertyGrid.Size;
            this.tabSolution_Property.DisplayLocation =
                new Point(this.Location.X + this.Width - 200, this.Location.Y + 100);
            this.tabSolution_Property.FloatingSize = this.controlfilteredPropertyGrid.Size;
            dockManager.Contents.Add(this.tabSolution_Property);
            dockManager.AddContentWithState(this.tabSolution_Property, State.Floating);

            //添加可隐藏的资源管理器窗口
            this.tabSolution_TreeView = new Content(this.dockManager);
            this.tabSolution_TreeView.Control = this.solutionTreeView;
            this.tabSolution_TreeView.FullTitle = "资源管理器";
            this.tabSolution_TreeView.Title = "资源管理器";
            this.tabSolution_TreeView.AutoHideSize = this.solutionTreeView.Size;
            this.tabSolution_TreeView.DisplaySize = this.solutionTreeView.Size;

            //添加可隐藏的工程管理器窗口
            this.tabSolution_ListBox = new Content(dockManager);
            this.tabSolution_ListBox.Control = this.ProListBox;
            this.tabSolution_ListBox.FullTitle = "工程管理器";
            this.tabSolution_ListBox.Title = "工程管理器";
            this.tabSolution_ListBox.AutoHideSize = this.ProListBox.Size;
            this.tabSolution_ListBox.DisplaySize = this.ProListBox.Size;

            Zone zone = dockManager.CreateZoneForContent(State.DockRight);
            dockManager.ReorderZoneToInnerMost(zone);
            dockManager.Contents.Add(this.tabSolution_ListBox);
            dockManager.AddContentToZone(this.tabSolution_ListBox, zone, 0);
            dockManager.Contents.Add(this.tabSolution_TreeView);
            dockManager.AddContentToZone(this.tabSolution_TreeView, zone, 1);

            //添加可隐藏的错误列表窗口
            this.tabSolution_ErrorBox = new Content(this.dockManager);
            this.tabSolution_ErrorBox.Control = this.errorForm;
            this.tabSolution_ErrorBox.FullTitle = "错误列表";
            this.tabSolution_ErrorBox.Title = "错误列表";
            this.tabSolution_ErrorBox.AutoHideSize = this.errorForm.Size;
            this.tabSolution_ErrorBox.DisplaySize = this.errorForm.Size;
            this.dockManager.Contents.Add(this.tabSolution_ErrorBox);
            this.dockManager.AddContentWithState(this.tabSolution_ErrorBox, State.DockBottom);

            //为隐藏窗口添加关闭事件处理函数,当隐藏窗口关闭时设置响应窗口状态栏的状态
            this.dockManager.ContentHidden +=
                new DockingManager.ContentHandler(dockingManager_Controls_ContentHidden);
        }