⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zonesequence.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 4 页
字号:
												// Keep count of total left to grab
												diff -= target.ZoneArea;
		
												// Window no longer has any ZoneArea											
												target.ZoneArea = 0m;
											}
											else
											{
												// Allocate it extra space
												target.ZoneArea -= extra;

												// Keep count of total left to grab
												diff -= extra;
											}
										}
									}
								}
							}
						}

						w.ZoneArea = newSpace;
					}
				}
			}

			// Recalculate the size and position of each Window and resize bar
			RepositionControls();
		}

        protected void AddHotZoneWithIndex(HotZoneCollection collection, Rectangle zoneArea, int length, int index)
        {
            // Find hot area and new size for first docking position
            Rectangle hotArea = zoneArea;
            Rectangle newSize = zoneArea;

            if (_direction == Direction.Vertical)
            {
                hotArea.Height = _hotVectorBeforeControl;
                newSize.Height = length;
            }
            else
            {
                hotArea.Width = _hotVectorBeforeControl;
                newSize.Width = length;
            }

            collection.Add(new HotZoneSequence(hotArea, newSize, this, index));				
        }
		
        protected override void OnWindowsClearing()
        {
            base.OnWindowsClearing();

            // Make sure no Window is recorded as maximized
            _maximizedWindow = null;

            // Remove all child controls
            Controls.Clear();

            if (!this.AutoDispose)
            {
                // Add back the Zone resize bar
                Controls.Add(_resizeBar);

                Invalidate();
            }
        }

        protected override void OnWindowInserted(int index, object value)
        {
            base.OnWindowInserted(index, value);

            Window w = value as Window;

            // Is this the first Window entry?
            if (_windows.Count == 1)
            {
                // Use size of the Window to determine our new size
                Size wSize = w.Size;

                // Adjust to account for the ResizeBar
                switch(this.Dock)
                {
                    case DockStyle.Left:
                    case DockStyle.Right:
                        wSize.Width += _resizeBar.Width;
                        break;
                    case DockStyle.Top:
                    case DockStyle.Bottom:
                        wSize.Height += _resizeBar.Height;
                        break;
                }

                this.Size = wSize;

                // Add the Window to the appearance
                Controls.Add(w);

                // Reposition to the start of the collection
                Controls.SetChildIndex(w, 0);
            }
            else
            {
                ResizeBar bar = new ResizeBar(_direction, this);

                // Add the bar and Window
                Controls.Add(bar);
                Controls.Add(w);

                // Adding at start of collection?
                if (index == 0)
                {
                    // Reposition the bar and Window to start of collection
                    Controls.SetChildIndex(bar, 0);
                    Controls.SetChildIndex(w, 0);
                }
                else
                {
                    int	pos = index * 2 - 1;

                    // Reposition the bar and Window to correct relative ordering
                    Controls.SetChildIndex(bar, pos++);
                    Controls.SetChildIndex(w, pos);
                }
            }

            // Allocate space for the new Window from other Windows
            AllocateWindowSpace(w);

            // Recalculate the size and position of each Window and resize bar
            RepositionControls();

            // Inform all interested parties of possible change in maximized state
            OnRefreshMaximize(EventArgs.Empty);
        }

        protected override void OnWindowRemoving(int index, object value)
        {
            base.OnWindowRemoving(index, value);

            Window w = value as Window;

            // If the Window being removed the maximized one?
            if (_maximizedWindow == w)
                _maximizedWindow = null;

            // Is this the only Window entry?
            if (_windows.Count == 1)
            {
                // Remove Window from appearance

				// Use helper method to circumvent form Close bug
				ControlHelper.RemoveAt(this.Controls, 0);
            }
            else
            {
                int pos = 0;

                // Calculate position of Window to remove				
                if (index != 0)
                    pos = index * 2 - 1;

                // Remove Window and bar 

				// Use helper method to circumvent form Close bug
				ControlHelper.RemoveAt(this.Controls, pos);
				ControlHelper.RemoveAt(this.Controls, pos);
            }

            // Redistribute space taken up by Window to other windows
            RemoveWindowSpace(w);
        }

        protected override void OnWindowRemoved(int index, object value)
        {
            base.OnWindowRemoved(index, value);

            // Recalculate the size and position of each Window and resize bar
            RepositionControls();

            // Inform all interested parties of possible change in maximized state
            OnRefreshMaximize(EventArgs.Empty);
        }

        protected void AllocateWindowSpace(Window w)
        {
            // Is this the only Window?
            if (_windows.Count == 1)
            {
                // Give it all the space
                w.ZoneArea = 100m;
            }
            else
            {
                // Calculate how much space it should have
                Decimal newSpace = 100m / _windows.Count;

                // How much space should we steal from each of the others
                Decimal reduceSpace = newSpace / (_windows.Count - 1);

                // Actual space acquired
                Decimal allocatedSpace = 0m;

                foreach(Window entry in _windows)
                {
                    if (entry != w)
                    {
                        // How much space the entry currently has
                        Decimal currentSpace = entry.ZoneArea;

                        // How much space to steal from it
                        Decimal xferSpace = reduceSpace;

                        // Does it have at least the requested amount of space?
                        if (currentSpace < xferSpace)
                            xferSpace = currentSpace;

                        // Transfer the space across
                        currentSpace -= xferSpace;

                        // Round the sensible number of decimal places
                        currentSpace = Decimal.Round(currentSpace, _spacePrecision);

                        // Update window with new space allocation
                        entry.ZoneArea = currentSpace;

                        allocatedSpace += currentSpace;
                    }
                }

                // Assign allocated space to new window
                w.ZoneArea = 100m - allocatedSpace;
            }
        }

        protected void ModifyWindowSpace(Window w, int vector)
        {
            // Remove any maximized state
            if (_maximizedWindow != null)
            {
                // Make the maximized Window have all the space
                foreach(Window entry in _windows)
                {
                    if (entry == _maximizedWindow)
                        entry.ZoneArea = 100m;
                    else
                        entry.ZoneArea = 0m; 
                }

                // Remove maximized state
                _maximizedWindow = null;

                // Inform all interested parties of change
                OnRefreshMaximize(EventArgs.Empty);
            }

            Rectangle clientRect = this.ClientRectangle;

            RepositionZoneBar(ref clientRect);

            // Space available for allocation
            int space;

            // New pixel length of the modified Window
            int newLength = vector;
			
            if (_direction == Direction.Vertical)
            {
                space = clientRect.Height;

                // New pixel size is requested change plus original 
                // height minus the minimal size that is always added
                newLength += w.Height;
                newLength -= w.MinimalSize.Height;
            }
            else
            {
                space = clientRect.Width;

                // New pixel size is requested change plus original 
                // width minus the minimal size that is always added
                newLength += w.Width;
                newLength -= w.MinimalSize.Width;
            }

            int barSpace = 0;

            // Create temporary array of working values
            Position[] positions = new Position[Controls.Count - 1];

            // Pass 1, allocate all the space needed for each ResizeBar and the 
            //         minimal amount of space that each Window requests. 
            AllocateMandatorySizes(ref positions, ref barSpace, ref space);

            // What is the new percentage it needs?
            Decimal newPercent = 0m;

            // Is there any room to allow a percentage calculation
            if ((newLength > 0) && (space > 0))
                newPercent = (Decimal)newLength / (Decimal)space * 100;

            // What is the change in area
            Decimal reallocate = newPercent - w.ZoneArea;

            // Find the Window after this one
            Window nextWindow = _windows[_windows.IndexOf(w) + 1];

            if ((nextWindow.ZoneArea - reallocate) < 0m)
                reallocate = nextWindow.ZoneArea;
	
            // Modify the Window in question
            w.ZoneArea += reallocate;

            // Reverse modify the Window afterwards
            nextWindow.ZoneArea -= reallocate;
			
            // Update the visual appearance
            RepositionControls();
        }

        protected Decimal ReduceAreaEvenly(int thisIndex, Decimal windowAllocation)
        {
            Decimal removed = 0m;

            // Process each Window after this one in the collection
            for(int index=thisIndex + 1; index<_windows.Count; index++)
            {
                Decimal zoneArea = _windows[index].ZoneArea;

                if (zoneArea > 0m)
                {
                    if (zoneArea >= windowAllocation)
                    {
                        // Reduce the area available for this Window
                        _windows[index].ZoneArea -= windowAllocation;

                        // Keep total of all area removed
                        removed += windowAllocation;
                    }
                    else
                    {
                        // Remove all the area from this Window
                        _windows[index].ZoneArea = 0m;

                        // Keep total of all area removed
                        removed += zoneArea;
                    }
                }
            }

            return removed;
        }
		
        protected void RemoveWindowSpace(Window w)
        {
            // Is there only a single Window left?
            if (_windows.Count == 1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -