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

📄 zonesequence.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 4 页
字号:
            {
                // Give it all the space
                _windows[0].ZoneArea = 100m;
            }
            else
            {
                // Is there any space to reallocate?
                if (w.ZoneArea > 0)
                {
                    // Total up all the values
                    Decimal totalAllocated = 0m;

                    // How much space should we add to each of the others
                    Decimal freedSpace = w.ZoneArea / (_windows.Count - 1);

                    foreach(Window entry in _windows)
                    {
                        if (entry != w)
                        {
                            // We only retain a sensible level of precision
                            Decimal newSpace = Decimal.Round(entry.ZoneArea + freedSpace, _spacePrecision);                            

                            // Assign back new space
                            entry.ZoneArea = newSpace;
                            
                            // Total up all space so far 
                            totalAllocated += newSpace;
                        }
                    }

                    // Look for minor errors due not all fractions can be accurately represented in binary!
                    if (totalAllocated > 100m)
                    {
                        Decimal correction = totalAllocated - 100m;

                        // Remove from first entry
                        foreach(Window entry in _windows)
                        {
                            if (entry != w)
                            {
                                // Apply correction to this window
                                entry.ZoneArea = totalAllocated - 100m;
                                break;
                            }
                        }
                    }
                    else if (totalAllocated < 100m)
                    {
                        Decimal correction = 100m - totalAllocated;

                        // Remove from first entry
                        foreach(Window entry in _windows)
                        {
                            if (entry != w)
                            {
                                // Apply correction to this window
                                entry.ZoneArea += 100m - totalAllocated;
                                break;
                            }
                        }
                    }

                    // Window no longer has any space
                    w.ZoneArea = 0m;
                }
            }
        }

        protected void RepositionControls()
        {
			// Caller has requested that this call be ignored
			if (_suppressReposition)
			{
				_suppressReposition = false;
				return;
			}

            Rectangle clientRect = this.ClientRectangle;

            RepositionZoneBar(ref clientRect);

            if (_windows.Count > 0)
            {
                // Space available for allocation
                int space;
				
                // Starting position of first control 
                int delta;

                if (_direction == Direction.Vertical)
                {
                    space = clientRect.Height;
                    delta = clientRect.Top;
                }
                else
                {
                    space = clientRect.Width;
                    delta = clientRect.Left;
                }

                // Ensure this is not negative
                if (space < 0)
                    space = 0;

                int barSpace = 0;
                int allocation = space;

                // 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);

                // If there any more space left
                if (space > 0)
                {
                    // Pass 2, allocate any space left over according to the request percent 
                    //         area that each Window would like to achieve.
                    AllocateRemainingSpace(ref positions, space);
                }

                // Pass 3, reposition the controls according to allocated values.
                RepositionControls(ref positions, clientRect, delta);
            }
        }

        protected void AllocateMandatorySizes(ref Position[] positions, ref int barSpace, ref int space)
        {
            // Process each control (except last which is the Zone level ResizeBar)
            for(int index=0; index<(Controls.Count - 1); index++)
            {
                ResizeBar bar = Controls[index] as ResizeBar;

                if (bar != null)
                {
                    // Length needed is depends on direction 
                    positions[index].length = bar.Length;

                    // Add up how much space was allocated to ResizeBars
                    barSpace += positions[index].length;
                }
                else
                {
                    Window w = Controls[index] as Window;

                    if (w != null)
                    {
                        Size minimal = w.MinimalSize;

                        // Length needed is depends on direction 
                        if (_direction == Direction.Vertical)
                            positions[index].length = minimal.Height;
                        else
                            positions[index].length = minimal.Width;
                    }
                }

                // Reduce available space by that just allocated
                space -= positions[index].length;
            }			
        }

        protected void AllocateRemainingSpace(ref Position[] positions, int windowSpace)
        {
            // Space allocated so far
            int allocated = 0;

            // Process each control (except last which is the Zone level ResizeBar)
            for(int index=0; index<(Controls.Count - 1); index++)
            {
                Window w = Controls[index] as Window;

                // If no window is maximized then as long as the control is a window we enter the if statement,
                // If a window is maximized then we only enter the if statement if this is the maximzied one
                if ((w != null) && ((_maximizedWindow == null) || ((_maximizedWindow != null) && (_maximizedWindow == w))))
                {
                    // How much of remaining space does the Window request to have?
                    int extra;
					
                    if (_maximizedWindow == null)				
                    {
                        extra = (int)(windowSpace / 100m * w.ZoneArea);

                        // Is this the last Window to be positioned?
                        if (index == (Controls.Count - 1))
                        {
                            // Use up all the remaining space, this handles the case of 
                            // the above vector calculation giving rounding errors so that
                            // the last element needs adusting to fill exactly all the 
                            // available space
                            extra = windowSpace - allocated;
                        }
                    }
                    else
                    {
                        extra = windowSpace - allocated;
                    }

                    // Add the extra space to any existing space it has
                    positions[index].length += extra;

                    // Keep count of all allocated so far
                    allocated += extra;
                }
            }
        }

        protected void RepositionControls(ref Position[] positions, Rectangle clientRect, int delta)
        {
            // Process each control (except last which is the Zone level ResizeBar)
            for(int index=0; index<(Controls.Count - 1); index++)
            {
                int newDelta = positions[index].length;

                ResizeBar bar = Controls[index] as ResizeBar;

                if (bar != null)
                {
                    if (_direction == Direction.Vertical)
                    {
                        // Set new position
                        bar.Location = new Point(clientRect.X, delta);
                        bar.Width = clientRect.Width;
                        bar.Height = newDelta;

                        // Move delta down to next position
                        delta += newDelta;
                    }
                    else
                    {
                        // Set new position
                        bar.Location = new Point(delta, clientRect.Y);
                        bar.Height = clientRect.Height;
                        bar.Width = newDelta;

                        // Move delta across to next position
                        delta += newDelta;
                    }
                }
                else
                {
                    Window w = Controls[index] as Window;

                    if (w != null)
                    {
                        if (newDelta == 0)
                            w.Hide();
                        else
                        {
                            // Set new position/size based on direction
                            if (_direction == Direction.Vertical)
                            {
                                w.Location = new Point(clientRect.X, delta);
                                w.Width = clientRect.Width;
                                w.Height = newDelta;
                            }
                            else
                            {
                                w.Location = new Point(delta, clientRect.Y);
                                w.Height = clientRect.Height;
                                w.Width = newDelta;
                            }

                            if (!w.Visible)
                                w.Show();

                            // Move delta to next position
                            delta += newDelta;
                        }
                    }
                }
            }			
        }

        protected void RepositionZoneBar(ref Rectangle clientRect)
        {
            Rectangle barRect;

            int length = _resizeBar.Length;
			
			// We only want a resizeBar when actually docked against an edge
			bool resizeBarPresent = ((this.Dock != DockStyle.Fill) && (this.Dock != DockStyle.None));

            // Define the correct direction for the resize bar and new Zone position
            switch(_state)
            {
                case State.DockLeft:
                    _resizeBar.Direction = Direction.Horizontal;
                    barRect = new Rectangle(this.Width - length, 0, length, this.Height);
					
					if (resizeBarPresent)
						clientRect.Width -= length;
                    break;
                case State.DockTop:
                    _resizeBar.Direction = Direction.Vertical;
                    barRect = new Rectangle(0, this.Height - length, this.Width, length);

					if (resizeBarPresent)
	                    clientRect.Height -= length;
                    break;
                case State.DockRight:
                    _resizeBar.Direction = Direction.Horizontal;
                    barRect = new Rectangle(0, 0, length, this.Height);

					if (resizeBarPresent)
					{
						clientRect.X += length;
						clientRect.Width -= length;
					}
                    break;
                case State.DockBottom:
                    _resizeBar.Direction = Direction.Vertical;
                    barRect = new Rectangle(0, 0, this.Width, length);

					if (resizeBarPresent)
					{
						clientRect.Y += length;
						clientRect.Height -= length;
					}
                    break;
                case State.Floating:
                default:
                    _resizeBar.Direction = Direction.Horizontal;
                    barRect = new Rectangle(0, 0, 0, 0);
                    break;
            }

			if (resizeBarPresent)
			{
				// Reposition the Zone level resize bar control
				_resizeBar.Location = new Point(barRect.X, barRect.Y);
				_resizeBar.Size = new Size(barRect.Width, barRect.Height);
				
				if (!_resizeBar.Visible)
					_resizeBar.Show();
			}
			else
			{
				if (_resizeBar.Visible)
					_resizeBar.Hide();
			}
        }

        protected override void OnResize(EventArgs e)
        {
            // Need to recalculate based on new window space
            RepositionControls();

            base.OnResize(e);
        }
    }
}

⌨️ 快捷键说明

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