?? autohidepanel.cs
字號(hào):
// *****************************************************************************
//
// (c) Crownwood Consulting Limited 2002
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Crownwood Consulting
// Limited, Haxey, North Lincolnshire, England and are supplied subject to
// licence terms.
//
// Magic Version 1.7 www.dotnetmagic.com
// *****************************************************************************
using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using Crownwood.Magic.Win32;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Collections;
namespace Crownwood.Magic.Docking
{
[ToolboxItem(false)]
public class AutoHidePanel : Panel, IMessageFilter
{
[ToolboxItem(false)]
protected class AutoHostPanel : Panel, IResizeSource
{
protected Edge _borderEdge;
protected ResizeAutoBar _resizeAutoBar;
protected AutoHidePanel _autoHidePanel;
protected DockingManager _manager;
public AutoHostPanel(DockingManager manager, AutoHidePanel autoHidePanel, Edge borderEdge)
{
// Remember parameters
_manager = manager;
_autoHidePanel = autoHidePanel;
_borderEdge = borderEdge;
Direction direction;
if ((borderEdge == Edge.Left) || (borderEdge == Edge.Right))
direction = Direction.Horizontal;
else
direction = Direction.Vertical;
// Create a resizing bar
_resizeAutoBar = new ResizeAutoBar(direction, this);
// Add to the display
Controls.Add(_resizeAutoBar);
// Define correct position based on Edge
switch(_borderEdge)
{
case Edge.Left:
_resizeAutoBar.Dock = DockStyle.Left;
break;
case Edge.Right:
_resizeAutoBar.Dock = DockStyle.Right;
break;
case Edge.Top:
_resizeAutoBar.Dock = DockStyle.Top;
break;
case Edge.Bottom:
_resizeAutoBar.Dock = DockStyle.Bottom;
break;
}
}
public Size ResizeBarSize()
{
return _resizeAutoBar.Size;
}
public int MinimumWidth
{
get { return _resizeAutoBar.Width * 5; }
}
public int MinimumHeight
{
get { return _resizeAutoBar.Height * 6; }
}
public Color ResizeBarColor
{
get { return _manager.ResizeBarColor; }
}
public int ResizeBarVector
{
get { return _manager.ResizeBarVector; }
}
public VisualStyle Style
{
get { return _manager.Style; }
}
public Color BackgroundColor
{
get { return _manager.BackColor; }
}
public bool CanResize(ResizeBar bar)
{
return true;
}
public bool StartResizeOperation(ResizeBar bar, ref Rectangle screenBoundary)
{
// Set focus into the WCT to prevent it siding away during resize
_autoHidePanel.SetFocusToWCT();
// Define resize boundary as the inner area of the Form containing the Zone
screenBoundary = this.Parent.RectangleToScreen(_manager.InnerResizeRectangle(this));
// Find the screen limits of this Zone
Rectangle panelBoundary = RectangleToScreen(this.ClientRectangle);
int minHeight = this.MinimumHeight;
int minWidth = this.MinimumWidth;
// Restrict resize based on which edge we are attached against
switch(_borderEdge)
{
case Edge.Bottom:
{
// Restrict Zone being made smaller than its minimum height
int diff = panelBoundary.Top - screenBoundary.Top + minHeight;
screenBoundary.Y += diff;
screenBoundary.Height -= diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Height;
screenBoundary.Height -= innerMinimumWidth;
}
break;
case Edge.Top:
{
// Restrict Zone being made smaller than its minimum height
int diff = panelBoundary.Bottom - screenBoundary.Bottom - minHeight;
screenBoundary.Height += diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Height;
screenBoundary.Y += innerMinimumWidth;
screenBoundary.Height -= innerMinimumWidth;
}
break;
case Edge.Right:
{
// Restrict Zone being made smaller than its minimum width
int diff = panelBoundary.Left - screenBoundary.Left + minWidth;
screenBoundary.X += diff;
screenBoundary.Width -= diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Width;
screenBoundary.Width -= innerMinimumWidth;
}
break;
case Edge.Left:
{
// Restrict Zone being made smaller than its minimum width
int diff = panelBoundary.Right - screenBoundary.Right - minWidth;
screenBoundary.Width += diff;
// Restrict Zone from making inner control smaller than minimum allowed
int innerMinimumWidth = _manager.InnerMinimum.Width;
screenBoundary.X += innerMinimumWidth;
screenBoundary.Width -= innerMinimumWidth;
}
break;
}
return true;
}
public void EndResizeOperation(ResizeBar bar, int delta)
{
switch(_borderEdge)
{
case Edge.Right:
Controls[1].Width += delta;
this.Width += delta;
_autoHidePanel.UpdateContentSize(Controls[1].Width, true);
break;
case Edge.Left:
Controls[1].Width -= delta;
this.Width -= delta;
this.Left += delta;
_autoHidePanel.UpdateContentSize(Controls[1].Width, true);
break;
case Edge.Bottom:
Controls[1].Height += delta;
this.Height += delta;
_autoHidePanel.UpdateContentSize(Controls[1].Height, false);
break;
case Edge.Top:
Controls[1].Height -= delta;
this.Height -= delta;
this.Top += delta;
_autoHidePanel.UpdateContentSize(Controls[1].Height, false);
break;
}
_autoHidePanel.DefineRectangles();
}
public void PropogateNameValue(PropogateName name, object value)
{
switch(name)
{
case PropogateName.BackColor:
this.BackColor = (Color)value;
Invalidate();
break;
}
// Pass onto the Resize bar control
_resizeAutoBar.PropogateNameValue(name, value);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
// Overriden to prevent background being painted
}
protected override void OnPaint(PaintEventArgs e)
{
// Overriden to paint just the inward facing edge
}
}
// Static fields
protected static int _num = 0;
protected static int _slideSteps = 4;
protected static int _slideInterval = 15;
protected static int _dismissInterval = 1000;
// Instance fields
protected int _number;
protected bool _killing;
protected bool _defaultColor;
protected bool _dismissRunning;
protected bool _slideRunning;
protected bool _ignoreDismiss;
protected bool _slideOut;
protected int _slideStep;
protected Timer _slideTimer;
protected Timer _dismissTimer;
protected Rectangle _slideRect;
protected Rectangle _rememberRect;
protected DockingManager _manager;
protected AutoHostPanel _currentPanel;
protected WindowContentTabbed _currentWCT;
public AutoHidePanel(DockingManager manager, DockStyle dockEdge)
{
// Define initial state
_number = _num++;
_defaultColor = true;
_dismissRunning = false;
_slideRunning = false;
_ignoreDismiss = false;
_killing = false;
_manager = manager;
_currentWCT = null;
_currentPanel = null;
_slideRect = new Rectangle();
_rememberRect = new Rectangle();
// Get the minimum vector length used for sizing
int vector = TabStub.TabStubVector(this.Font);
// Use for both directions, the appropriate one will be ignored because of docking style
this.Size = new Size(vector, vector);
// Dock ourself against requested position
this.Dock = dockEdge;
// We should be hidden until some Contents are added
this.Hide();
// We want to perform special action when container is resized
_manager.Container.Resize += new EventHandler(OnContainerResized);
// Add ourself to the application filtering list
Application.AddMessageFilter(this);
// Configuration timer objects
CreateTimers();
}
public void PropogateNameValue(PropogateName name, object value)
{
switch(name)
{
case PropogateName.BackColor:
this.BackColor = (Color)value;
Invalidate();
break;
case PropogateName.CaptionFont:
this.Font = (Font)value;
// Recalculate the window size
int vector = TabStub.TabStubVector(this.Font);
this.Size = new Size(vector, vector);
Invalidate();
break;
}
// Pass onto each TabStub instance
foreach(TabStub ts in Controls)
ts.PropogateNameValue(name, value);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -