📄 autohidepanel.cs
字号:
}
public void AddContentsAsGroup(ContentCollection contents)
{
// By default, insert new group at the end of display which is start of list
AddContentsAsGroup(contents, 0);
}
public void AddContentsAsGroup(ContentCollection contents, int index)
{
// Create new TabStub to represent the Contents
TabStub ts = new TabStub(_manager.Style);
// Set manager requested settings
ts.Font = _manager.CaptionFont;
ts.BackColor = _manager.BackColor;
ts.ForeColor = _manager.InactiveTextColor;
// Hook into events
ts.PageOver += new TabStub.TabStubIndexHandler(OnPageOver);
ts.PageClicked += new TabStub.TabStubIndexHandler(OnPageClicked);
ts.PagesLeave += new TabStub.TabStubHandler(OnPagesLeave);
// Add a page for each Content instance
foreach(Content c in contents)
{
// Create page object
Crownwood.Magic.Controls.TabPage page = new Crownwood.Magic.Controls.TabPage();
// Copy across the visual properties
page.Title = c.Title;
page.ImageList = c.ImageList;
page.ImageIndex = c.ImageIndex;
// Remember reference to Content it represents
page.Tag = c;
// Add into the stub
ts.TabPages.Add(page);
// Mark Content as being in AutoHide mode
c.AutoHidePanel = this;
c.AutoHidden = true;
}
State windowState = State.DockLeft;
// Define stub settings based on our docking position
switch(this.Dock)
{
case DockStyle.Left:
windowState = State.DockLeft;
ts.Edging = Edge.Left;
ts.Dock = DockStyle.Top;
break;
case DockStyle.Right:
windowState = State.DockRight;
ts.Edging = Edge.Right;
ts.Dock = DockStyle.Top;
break;
case DockStyle.Top:
windowState = State.DockTop;
ts.Edging = Edge.Top;
ts.Dock = DockStyle.Left;
break;
case DockStyle.Bottom:
windowState = State.DockBottom;
ts.Edging = Edge.Bottom;
ts.Dock = DockStyle.Left;
break;
}
// Add stub into the view
Controls.Add(ts);
// Set correct new position
Controls.SetChildIndex(ts, index);
// Each TabStub has a WCT created and ready to be shown when needed
WindowContentTabbed wct = _manager.CreateWindowForContent(null, new EventHandler(OnPageClose),
null, new EventHandler(OnPageAutoHide),
new ContextHandler(OnPageContextMenu)) as WindowContentTabbed;
// Add each Content instance in turn
foreach(Content c in contents)
wct.Contents.Add(c);
// By default the first Content added to a WCT will define the size
// of the WCT control. We need to override this to use the AutoHideSize
// from the first Content instead.
wct.Size = contents[0].AutoHideSize;
// Ensure Window caption bar reflects correct docking status
wct.State = windowState;
// Inform Window it should not allow user initiated redocking
wct.RedockAllowed = false;
// Hide tab selection from user
wct.TabControl.HideTabsMode = Magic.Controls.TabControl.HideTabsModes.HideAlways;
// Associate WCT with matching TabStub
ts.WindowContentTabbed = wct;
// Make sure this AutoHidePanel is visible
if (!this.Visible)
this.Show();
Invalidate();
}
protected void RemoveDisplayedWindow()
{
// Remove snooping of changes to focus
MonitorPanel(false);
if (_currentPanel != null)
{
// Remove the child WindowContentTabbed
ControlHelper.Remove(_currentPanel.Controls, _currentWCT);
// Remove Panel from managed container
ControlHelper.Remove(_manager.Container.Controls, _currentPanel);
}
if (_currentWCT != null)
{
// Restore the original sizes
_currentWCT.Width = _rememberRect.Width;
_currentWCT.Height = _rememberRect.Height;
}
if (_currentPanel != null)
{
// Destroy the panel
_currentPanel.Dispose();
_currentPanel = null;
}
}
protected void KillDisplayedWindow()
{
_killing = true;
// If dismiss timer running, then turn it off
StopDismissTimer();
// Remove content objects from WCT to update state
int count = _currentWCT.Contents.Count;
for(int index=0; index<count; index++)
{
// Remember reference to first content
Content c = _currentWCT.Contents[0];
// Remove it from collection
_currentWCT.Contents.RemoveAt(0);
}
// Get rid of the displayed Panel immediately
RemoveDisplayedWindow();
// No longer considered the shown window
_currentWCT.Dispose();
_currentWCT = null;
_killing = false;
}
protected void UpdateContentSize(int newVector, bool isWidth)
{
// Ensure we have a Panel to work with
if (_currentPanel != null)
{
// Should always have WCT, but just in case...
if (_currentWCT != null)
{
// Modify the remembered AutoHide vector
foreach(Content c in _currentWCT.Contents)
{
// Get existing Size
Size s = c.AutoHideSize;
// Update appropriate vector
if (isWidth)
s.Width = newVector;
else
s.Height = newVector;
// Save it away
c.AutoHideSize = s;
}
}
}
}
protected void DefineRectangles()
{
// Store original WCT size to be restored later
_rememberRect = _currentWCT.ClientRectangle;
// Default showing size to that requested by WCT
_slideRect = _rememberRect;
// Find actual available Form size for sliding into
Rectangle availableSize = _manager.InnerResizeRectangle(this);
// Reduce actual displayed size by limits of Form size
if (availableSize.Width < _slideRect.Width)
_slideRect.Width = availableSize.Width;
if (availableSize.Height < _slideRect.Height)
_slideRect.Height = availableSize.Height;
}
protected void SetFocusToWCT()
{
// Ensure we have a Panel to work with
if (_currentPanel != null)
{
// If the Panel does not already contain the focus...
if (!_currentWCT.ContainsFocus)
{
_currentWCT.Focus();
_currentWCT.Refresh();
}
}
}
protected void OnPageClicked(TabStub sender, int pageIndex)
{
// Remove any showing auto hide windows except our own
_manager.RemoveShowingAutoHideWindowsExcept(this);
// A click is the same as an immediate hover over
OnPageOver(sender, pageIndex);
// A click implies the panel takes the focus immediately
SetFocusToWCT();
}
protected void OnPageOver(TabStub sender, int pageIndex)
{
// Remove any showing auto hide windows except our own
_manager.RemoveShowingAutoHideWindowsExcept(this);
// No need for running timer, this action supercedes it
StopDismissTimer();
// Hovering over a different TabStub?
if (_currentWCT != sender.WindowContentTabbed)
{
// Remove any currently displayed Panel/WCT
if (_currentWCT != null)
RemoveDisplayedWindow();
}
else
{
// Different tab in the same TabStub?
if (pageIndex != _currentWCT.TabControl.SelectedIndex)
{
// Remove any currently displayed Panel/WCT
if (_currentWCT != null)
RemoveDisplayedWindow();
}
else
{
// Hover over the current window, so do nothing
return;
}
}
Edge borderEdge = Edge.None;
// Define which edge of the host panel shown have a border drawn
switch(this.Dock)
{
case DockStyle.Left:
borderEdge = Edge.Right;
break;
case DockStyle.Right:
borderEdge = Edge.Left;
break;
case DockStyle.Top:
borderEdge = Edge.Bottom;
break;
case DockStyle.Bottom:
borderEdge = Edge.Top;
break;
}
// Create a Panel that will host the actual WindowContentTabbed control,
// the Panel is resized to slide into/from view. The WCT is a fixed size
// within the Panel and so only the partial view of the WCT is shown and
// at any point in time. Cannot resize the WCT into view as it would keep
// repainting the caption details and effect and docking items inside it.
_currentPanel = new AutoHostPanel(_manager, this, borderEdge);
// Do not show it until we have resizing it as needed
_currentPanel.Hide();
// Get access to the WindowContentTabbed that is to be hosted
_currentWCT = sender.WindowContentTabbed;
// Select the correct page for view in the WCT
_currentWCT.TabControl.SelectedIndex = pageIndex;
// Place the WCT inside the host Panel
_currentPanel.Controls.Add(_currentWCT);
// Now add the Panel to the container display
_manager.Container.Controls.Add(_currentPanel);
// Make it top of the Z-Order
_manager.Container.Controls.SetChildIndex(_currentPanel, 0);
// Define the remember and slide rectangle values
DefineRectangles();
// Set the modified WCT size
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -