📄 dockingmanager.cs
字号:
c.ContentLeavesFloating();
else
c.ContentBecomesFloating();
}
// Remove the Content from its current WindowContent
c.ParentWindowContent.Contents.Remove(c);
}
else
{
// If target zone is floating window then we are no longer docked
if (z.State == State.Floating)
c.Docked = false;
}
// Create a new WindowContent instance according to our style
Window w = CreateWindowForContent(c);
// Add the Window to the Zone at given position
z.Windows.Insert(index, w);
// Enable generation hiding/hidden/shown events
_surpressVisibleEvents--;
// Generate event to indicate content is now visible
OnContentShown(c);
return w;
}
public Rectangle InnerResizeRectangle(Control source)
{
// Start with a rectangle that represents the entire client area
Rectangle client = _container.ClientRectangle;
int count = _container.Controls.Count;
int inner = _container.Controls.IndexOf(_innerControl);
int sourceIndex = _container.Controls.IndexOf(source);
// Process each control outside the inner control
for(int index=count-1; index>inner; index--)
{
Control item = _container.Controls[index];
bool insideSource = (index < sourceIndex);
switch(item.Dock)
{
case DockStyle.Left:
client.Width -= item.Width;
client.X += item.Width;
if (insideSource)
client.Width -= item.Width;
break;
case DockStyle.Right:
client.Width -= item.Width;
if (insideSource)
{
client.Width -= item.Width;
client.X += item.Width;
}
break;
case DockStyle.Top:
client.Height -= item.Height;
client.Y += item.Height;
if (insideSource)
client.Height -= item.Height;
break;
case DockStyle.Bottom:
client.Height -= item.Height;
if (insideSource)
{
client.Height -= item.Height;
client.Y += item.Height;
}
break;
case DockStyle.Fill:
case DockStyle.None:
break;
}
}
return client;
}
public void ReorderZoneToInnerMost(Zone zone)
{
int index = 0;
// If there is no control specified as the one for all Zones to be placed
// in front of then simply add the Zone at the start of the list so it is
// in front of all controls.
if (_innerControl != null)
{
// Find position of specified control and place after it in the list
// (hence adding one to the returned value)
index = _container.Controls.IndexOf(_innerControl) + 1;
}
// Find current position of the Zone to be repositioned
int current = _container.Controls.IndexOf(zone);
// If the old position is before the new position then we need to
// subtract one. As the collection will remove the Control from the
// old position before inserting it in the new, thus reducing the index
// by 1 before the insert occurs.
if (current < index)
index--;
// Found a Control that is not a Zone, so need to insert straight it
_container.Controls.SetChildIndex(zone, index);
// Manageing Zones should remove display AutoHide windows
RemoveShowingAutoHideWindows();
}
public void ReorderZoneToOuterMost(Zone zone)
{
// Get index of the outer control (minus AutoHidePanel's)
int index = OuterControlIndex();
// Find current position of the Zone to be repositioned
int current = _container.Controls.IndexOf(zone);
// If the old position is before the new position then we need to
// subtract one. As the collection will remove the Control from the
// old position before inserting it in the new, thus reducing the index
// by 1 before the insert occurs.
if (current < index)
index--;
// Found a Control that is not a Zone, so need to insert straight it
_container.Controls.SetChildIndex(zone, index);
// Manageing Zones should remove display AutoHide windows
RemoveShowingAutoHideWindows();
}
public int OuterControlIndex()
{
int index = _container.Controls.Count;
// If there is no control specified as the one for all Zones to be placed behind
// then simply add the Zone at the end of the list so it is behind all controls.
if (_outerControl != null)
{
// Find position of specified control and place before it in the list
index = _container.Controls.IndexOf(_outerControl);
}
// Adjust backwards to prevent being after any AutoHidePanels
for(; index>0; index--)
if (!(_container.Controls[index-1] is AutoHidePanel))
break;
return index;
}
public void RemoveShowingAutoHideWindows()
{
_ahpLeft.RemoveShowingWindow();
_ahpRight.RemoveShowingWindow();
_ahpTop.RemoveShowingWindow();
_ahpBottom.RemoveShowingWindow();
}
internal void RemoveShowingAutoHideWindowsExcept(AutoHidePanel except)
{
if (except != _ahpLeft)
_ahpLeft.RemoveShowingWindow();
if (except != _ahpRight)
_ahpRight.RemoveShowingWindow();
if (except != _ahpTop)
_ahpTop.RemoveShowingWindow();
if (except != _ahpBottom)
_ahpBottom.RemoveShowingWindow();
}
public void BringAutoHideIntoView(Content c)
{
if (_ahpLeft.ContainsContent(c))
_ahpLeft.BringContentIntoView(c);
if (_ahpRight.ContainsContent(c))
_ahpRight.BringContentIntoView(c);
if (_ahpTop.ContainsContent(c))
_ahpTop.BringContentIntoView(c);
if (_ahpBottom.ContainsContent(c))
_ahpBottom.BringContentIntoView(c);
}
public void ValuesFromState(State newState, out DockStyle dockState, out Direction direction)
{
switch(newState)
{
case State.Floating:
dockState = DockStyle.Fill;
direction = Direction.Vertical;
break;
case State.DockTop:
dockState = DockStyle.Top;
direction = Direction.Horizontal;
break;
case State.DockBottom:
dockState = DockStyle.Bottom;
direction = Direction.Horizontal;
break;
case State.DockRight:
dockState = DockStyle.Right;
direction = Direction.Vertical;
break;
case State.DockLeft:
default:
dockState = DockStyle.Left;
direction = Direction.Vertical;
break;
}
}
public byte[] SaveConfigToArray()
{
return SaveConfigToArray(Encoding.Unicode);
}
public byte[] SaveConfigToArray(Encoding encoding)
{
// Create a memory based stream
MemoryStream ms = new MemoryStream();
// Save into the file stream
SaveConfigToStream(ms, encoding);
// Must remember to close
ms.Close();
// Return an array of bytes that contain the streamed XML
return ms.GetBuffer();
}
public void SaveConfigToFile(string filename)
{
SaveConfigToFile(filename, Encoding.Unicode);
}
public void SaveConfigToFile(string filename, Encoding encoding)
{
// Create/Overwrite existing file
FileStream fs = new FileStream(filename, FileMode.Create);
// Save into the file stream
SaveConfigToStream(fs, encoding);
// Must remember to close
fs.Close();
}
public void SaveConfigToStream(Stream stream, Encoding encoding)
{
XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding);
// Use indenting for readability
xmlOut.Formatting = Formatting.Indented;
// Always begin file with identification and warning
xmlOut.WriteStartDocument();
xmlOut.WriteComment(" Magic, The User Interface library for .NET (www.dotnetmagic.com) ");
xmlOut.WriteComment(" Modifying this generated file will probably render it invalid ");
// Associate a version number with the root element so that future version of the code
// will be able to be backwards compatible or at least recognise out of date versions
xmlOut.WriteStartElement("DockingConfig");
xmlOut.WriteAttributeString("FormatVersion", "5");
xmlOut.WriteAttributeString("InsideFill", _insideFill.ToString());
xmlOut.WriteAttributeString("InnerMinimum", ConversionHelper.SizeToString(_innerMinimum));
// We need to hide all content during the saving process, but then restore
// them back again before leaving so the user does not see any change
_container.SuspendLayout();
// Store a list of those content hidden during processing
ContentCollection hideContent = new ContentCollection();
// Let create a copy of the current contents in current order, because
// we cannot 'foreach' a collection that is going to be altered during its
// processing by the 'HideContent'.
ContentCollection origContents = _contents.Copy();
// Do not generate hiding/hidden/shown events
_surpressVisibleEvents++;
int count = origContents.Count;
// Hide in reverse order so that a ShowAll in forward order gives accurate restore
for(int index=count-1; index>=0; index--)
{
Content c = origContents[index];
c.RecordRestore();
c.SaveToXml(xmlOut);
// If visible then need to hide so that subsequent attempts to
// RecordRestore will not take its position into account
if (c.Visible)
{
hideContent.Insert(0, c);
HideContent(c);
}
}
// Allow an event handler a chance to add custom information after ours
OnSaveCustomConfig(xmlOut);
// Put content we hide back again
foreach(Content c in hideContent)
ShowContent(c);
// Enable generation of hiding/hidden/shown events
_surpressVisibleEvents--;
// Reapply any fill style required
AddInnerFillStyle();
_container.ResumeLayout();
// Terminate the root element and document
xmlOut.WriteEndElement();
xmlOut.WriteEndDocument();
// This should flush all actions and close the file
xmlOut.Close();
}
public void LoadConfigFromArray(byte[] buffer)
{
// Create a memory based stream
MemoryStream ms = new MemoryStream(buffer);
// Save into the file stream
LoadConfigFromStream(ms);
// Must remember to close
ms.Close();
}
public void LoadConfigFromFile(string filename)
{
// Open existing file
FileStream fs = new FileStream(filename, FileMode.Open);
// Load from the file stream
LoadConfigFromStream(fs);
// Must remember to close
fs.Close();
}
public void LoadConfigFromStream(Stream stream)
{
XmlTextReader xmlIn = new XmlTextReader(stream);
// Ignore whitespace, not interested
xmlIn.WhitespaceHandling = WhitespaceHandling.None;
// Moves the reader to the root element.
xmlIn.MoveToContent();
// Double check this has the correct element name
if (xmlIn.Name != "DockingConfig")
throw new ArgumentException("Root element must be 'DockingConfig'");
// Load the format version number
string version = xmlIn.GetAttribute(0);
string insideFill = xmlIn.GetAttribute(1);
string innerSize = xmlIn.GetAttribute(2);
// Convert format version from string to double
int formatVersion = (int)Convert.ToDouble(version);
// We can only load 3 upward version formats
if (formatVersion < 3)
throw new ArgumentException("Can only load Version 3 and upwards Docking Configuration files");
// Convert from string to proper types
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -