Added more using.

This commit is contained in:
Lex Li
2013-08-03 13:17:24 +08:00
parent 3945ea4ab3
commit 981adbb8f4
12 changed files with 317 additions and 267 deletions

View File

@@ -1061,6 +1061,7 @@ namespace WeifenLuo.WinFormsUI.Docking
public void FloatAt(Rectangle floatWindowBounds)
{
// TODO: where is the pane used?
DockPane pane = DockPanel.DockPaneFactory.CreateDockPane(Content, floatWindowBounds, true);
}

View File

@@ -372,9 +372,19 @@ namespace WeifenLuo.WinFormsUI.Docking
{
DragForm.Bounds = rect;
if (rect == Rectangle.Empty)
{
if (DragForm.Region != null)
{
DragForm.Region.Dispose();
}
DragForm.Region = new Region(Rectangle.Empty);
}
else if (DragForm.Region != null)
{
DragForm.Region.Dispose();
DragForm.Region = null;
}
}
private void SetDragForm(Rectangle rect, Region region)

View File

@@ -1,8 +1,6 @@
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using WeifenLuo.WinFormsUI.Docking;
using System.IO;
using System.Text;
using System.Xml;
@@ -214,14 +212,16 @@ namespace WeifenLuo.WinFormsUI.Docking
public static void SaveAsXml(DockPanel dockPanel, string fileName, Encoding encoding)
{
FileStream fs = new FileStream(fileName, FileMode.Create);
try
using (var fs = new FileStream(fileName, FileMode.Create))
{
SaveAsXml(dockPanel, fs, encoding);
}
finally
{
fs.Close();
try
{
SaveAsXml(dockPanel, fs, encoding);
}
finally
{
fs.Close();
}
}
}
@@ -232,148 +232,150 @@ namespace WeifenLuo.WinFormsUI.Docking
public static void SaveAsXml(DockPanel dockPanel, Stream stream, Encoding encoding, bool upstream)
{
XmlTextWriter xmlOut = new XmlTextWriter(stream, encoding);
// Use indenting for readability
xmlOut.Formatting = Formatting.Indented;
if (!upstream)
xmlOut.WriteStartDocument();
// Always begin file with identification and warning
xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment1);
xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment2);
// 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("DockPanel");
xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));
if (!Win32Helper.IsRunningOnMono)
using (var xmlOut = new XmlTextWriter(stream, encoding))
{
xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
}
xmlOut.Formatting = Formatting.Indented;
// Contents
xmlOut.WriteStartElement("Contents");
xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
foreach (IDockContent content in dockPanel.Contents)
{
xmlOut.WriteStartElement("Content");
xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("PersistString", content.DockHandler.PersistString);
xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
if (!upstream)
xmlOut.WriteStartDocument();
// Panes
xmlOut.WriteStartElement("Panes");
xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
foreach (DockPane pane in dockPanel.Panes)
{
xmlOut.WriteStartElement("Pane");
xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
// Always begin file with identification and warning
xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment1);
xmlOut.WriteComment(Strings.DockPanel_Persistor_XmlFileComment2);
// 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("DockPanel");
xmlOut.WriteAttributeString("FormatVersion", ConfigFileVersion);
xmlOut.WriteAttributeString("DockLeftPortion", dockPanel.DockLeftPortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockRightPortion", dockPanel.DockRightPortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockTopPortion", dockPanel.DockTopPortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockBottomPortion", dockPanel.DockBottomPortion.ToString(CultureInfo.InvariantCulture));
if (!Win32Helper.IsRunningOnMono)
{
xmlOut.WriteAttributeString("ActiveDocumentPane", dockPanel.Panes.IndexOf(dockPanel.ActiveDocumentPane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("ActivePane", dockPanel.Panes.IndexOf(dockPanel.ActivePane).ToString(CultureInfo.InvariantCulture));
}
// Contents
xmlOut.WriteStartElement("Contents");
xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
foreach (IDockContent content in pane.Contents)
xmlOut.WriteAttributeString("Count", dockPanel.Contents.Count.ToString(CultureInfo.InvariantCulture));
foreach (IDockContent content in dockPanel.Contents)
{
xmlOut.WriteStartElement("Content");
xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("ID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("PersistString", content.DockHandler.PersistString);
xmlOut.WriteAttributeString("AutoHidePortion", content.DockHandler.AutoHidePortion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("IsHidden", content.DockHandler.IsHidden.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("IsFloat", content.DockHandler.IsFloat.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
// DockWindows
xmlOut.WriteStartElement("DockWindows");
int dockWindowId = 0;
foreach (DockWindow dw in dockPanel.DockWindows)
{
xmlOut.WriteStartElement("DockWindow");
xmlOut.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
dockWindowId++;
xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteStartElement("NestedPanes");
xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
foreach (DockPane pane in dw.NestedPanes)
// Panes
xmlOut.WriteStartElement("Panes");
xmlOut.WriteAttributeString("Count", dockPanel.Panes.Count.ToString(CultureInfo.InvariantCulture));
foreach (DockPane pane in dockPanel.Panes)
{
xmlOut.WriteStartElement("Pane");
xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
NestedDockingStatus status = pane.NestedDockingStatus;
xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("ID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("DockState", pane.DockState.ToString());
xmlOut.WriteAttributeString("ActiveContent", dockPanel.Contents.IndexOf(pane.ActiveContent).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteStartElement("Contents");
xmlOut.WriteAttributeString("Count", pane.Contents.Count.ToString(CultureInfo.InvariantCulture));
foreach (IDockContent content in pane.Contents)
{
xmlOut.WriteStartElement("Content");
xmlOut.WriteAttributeString("ID", pane.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("RefID", dockPanel.Contents.IndexOf(content).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
// FloatWindows
RectangleConverter rectConverter = new RectangleConverter();
xmlOut.WriteStartElement("FloatWindows");
xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
foreach (FloatWindow fw in dockPanel.FloatWindows)
{
xmlOut.WriteStartElement("FloatWindow");
xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteStartElement("NestedPanes");
xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
foreach (DockPane pane in fw.NestedPanes)
// DockWindows
xmlOut.WriteStartElement("DockWindows");
int dockWindowId = 0;
foreach (DockWindow dw in dockPanel.DockWindows)
{
xmlOut.WriteStartElement("Pane");
xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
NestedDockingStatus status = pane.NestedDockingStatus;
xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteStartElement("DockWindow");
xmlOut.WriteAttributeString("ID", dockWindowId.ToString(CultureInfo.InvariantCulture));
dockWindowId++;
xmlOut.WriteAttributeString("DockState", dw.DockState.ToString());
xmlOut.WriteAttributeString("ZOrderIndex", dockPanel.Controls.IndexOf(dw).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteStartElement("NestedPanes");
xmlOut.WriteAttributeString("Count", dw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
foreach (DockPane pane in dw.NestedPanes)
{
xmlOut.WriteStartElement("Pane");
xmlOut.WriteAttributeString("ID", dw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
NestedDockingStatus status = pane.NestedDockingStatus;
xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
// FloatWindows
RectangleConverter rectConverter = new RectangleConverter();
xmlOut.WriteStartElement("FloatWindows");
xmlOut.WriteAttributeString("Count", dockPanel.FloatWindows.Count.ToString(CultureInfo.InvariantCulture));
foreach (FloatWindow fw in dockPanel.FloatWindows)
{
xmlOut.WriteStartElement("FloatWindow");
xmlOut.WriteAttributeString("ID", dockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("Bounds", rectConverter.ConvertToInvariantString(fw.Bounds));
xmlOut.WriteAttributeString("ZOrderIndex", fw.DockPanel.FloatWindows.IndexOf(fw).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteStartElement("NestedPanes");
xmlOut.WriteAttributeString("Count", fw.NestedPanes.Count.ToString(CultureInfo.InvariantCulture));
foreach (DockPane pane in fw.NestedPanes)
{
xmlOut.WriteStartElement("Pane");
xmlOut.WriteAttributeString("ID", fw.NestedPanes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("RefID", dockPanel.Panes.IndexOf(pane).ToString(CultureInfo.InvariantCulture));
NestedDockingStatus status = pane.NestedDockingStatus;
xmlOut.WriteAttributeString("PrevPane", dockPanel.Panes.IndexOf(status.PreviousPane).ToString(CultureInfo.InvariantCulture));
xmlOut.WriteAttributeString("Alignment", status.Alignment.ToString());
xmlOut.WriteAttributeString("Proportion", status.Proportion.ToString(CultureInfo.InvariantCulture));
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement();
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement(); // </FloatWindows>
xmlOut.WriteEndElement();
}
xmlOut.WriteEndElement(); // </FloatWindows>
xmlOut.WriteEndElement();
if (!upstream)
{
xmlOut.WriteEndDocument();
xmlOut.Close();
if (!upstream)
{
xmlOut.WriteEndDocument();
xmlOut.Close();
}
else
xmlOut.Flush();
}
else
xmlOut.Flush();
}
public static void LoadFromXml(DockPanel dockPanel, string fileName, DeserializeDockContent deserializeContent)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
try
using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
LoadFromXml(dockPanel, fs, deserializeContent);
}
finally
{
fs.Close();
try
{
LoadFromXml(dockPanel, fs, deserializeContent);
}
finally
{
fs.Close();
}
}
}
@@ -515,56 +517,61 @@ namespace WeifenLuo.WinFormsUI.Docking
public static void LoadFromXml(DockPanel dockPanel, Stream stream, DeserializeDockContent deserializeContent, bool closeStream)
{
if (dockPanel.Contents.Count != 0)
throw new InvalidOperationException(Strings.DockPanel_LoadFromXml_AlreadyInitialized);
XmlTextReader xmlIn = new XmlTextReader(stream);
xmlIn.WhitespaceHandling = WhitespaceHandling.None;
xmlIn.MoveToContent();
while (!xmlIn.Name.Equals("DockPanel"))
DockPanelStruct dockPanelStruct;
ContentStruct[] contents;
PaneStruct[] panes;
DockWindowStruct[] dockWindows;
FloatWindowStruct[] floatWindows;
using (var xmlIn = new XmlTextReader(stream) { WhitespaceHandling = WhitespaceHandling.None })
{
if (!MoveToNextElement(xmlIn))
xmlIn.MoveToContent();
while (!xmlIn.Name.Equals("DockPanel"))
{
if (!MoveToNextElement(xmlIn))
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
}
string formatVersion = xmlIn.GetAttribute("FormatVersion");
if (!IsFormatVersionValid(formatVersion))
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidFormatVersion);
dockPanelStruct = new DockPanelStruct();
dockPanelStruct.DockLeftPortion = Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.DockRightPortion = Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.DockTopPortion = Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.DockBottomPortion = Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.IndexActiveDocumentPane = Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"), CultureInfo.InvariantCulture);
dockPanelStruct.IndexActivePane = Convert.ToInt32(xmlIn.GetAttribute("ActivePane"), CultureInfo.InvariantCulture);
// Load Contents
MoveToNextElement(xmlIn);
if (xmlIn.Name != "Contents")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
contents = LoadContents(xmlIn);
// Load Panes
if (xmlIn.Name != "Panes")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
panes = LoadPanes(xmlIn);
// Load DockWindows
if (xmlIn.Name != "DockWindows")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
dockWindows = LoadDockWindows(xmlIn, dockPanel);
// Load FloatWindows
if (xmlIn.Name != "FloatWindows")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
floatWindows = LoadFloatWindows(xmlIn);
if (closeStream)
xmlIn.Close();
}
string formatVersion = xmlIn.GetAttribute("FormatVersion");
if (!IsFormatVersionValid(formatVersion))
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidFormatVersion);
DockPanelStruct dockPanelStruct = new DockPanelStruct();
dockPanelStruct.DockLeftPortion = Convert.ToDouble(xmlIn.GetAttribute("DockLeftPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.DockRightPortion = Convert.ToDouble(xmlIn.GetAttribute("DockRightPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.DockTopPortion = Convert.ToDouble(xmlIn.GetAttribute("DockTopPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.DockBottomPortion = Convert.ToDouble(xmlIn.GetAttribute("DockBottomPortion"), CultureInfo.InvariantCulture);
dockPanelStruct.IndexActiveDocumentPane = Convert.ToInt32(xmlIn.GetAttribute("ActiveDocumentPane"), CultureInfo.InvariantCulture);
dockPanelStruct.IndexActivePane = Convert.ToInt32(xmlIn.GetAttribute("ActivePane"), CultureInfo.InvariantCulture);
// Load Contents
MoveToNextElement(xmlIn);
if (xmlIn.Name != "Contents")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
ContentStruct[] contents = LoadContents(xmlIn);
// Load Panes
if (xmlIn.Name != "Panes")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
PaneStruct[] panes = LoadPanes(xmlIn);
// Load DockWindows
if (xmlIn.Name != "DockWindows")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
DockWindowStruct[] dockWindows = LoadDockWindows(xmlIn, dockPanel);
// Load FloatWindows
if (xmlIn.Name != "FloatWindows")
throw new ArgumentException(Strings.DockPanel_LoadFromXml_InvalidXmlFormat);
FloatWindowStruct[] floatWindows = LoadFloatWindows(xmlIn);
if (closeStream)
xmlIn.Close();
dockPanel.SuspendLayout(true);
dockPanel.DockLeftPortion = dockPanelStruct.DockLeftPortion;

View File

@@ -991,6 +991,11 @@ namespace WeifenLuo.WinFormsUI.Docking
Region region = new Region(new Rectangle(0, 0, this.Width, this.Height));
foreach (Rectangle rect in m_clipRects)
region.Exclude(rect);
if (Region != null)
{
Region.Dispose();
}
Region = region;
}
}

View File

@@ -441,10 +441,12 @@ namespace WeifenLuo.WinFormsUI.Docking
pts[0].X = (float)rect.X + (float)rect.Width / 2;
pts[0].Y = (float)rect.Y + (float)rect.Height / 2;
Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState);
Matrix matrix = new Matrix();
matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
matrix.TransformPoints(pts);
using (Matrix matrix = new Matrix())
{
matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
matrix.TransformPoints(pts);
}
return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F),
(int)(pts[0].Y - (float)rect.Width / 2 + .5F),

View File

@@ -319,67 +319,70 @@ namespace WeifenLuo.WinFormsUI.Docking
DockState dockState = tab.Content.DockHandler.DockState;
IDockContent content = tab.Content;
GraphicsPath path = GetTabOutline(tab, false, true);
Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor;
Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor;
LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode;
g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path);
g.DrawPath(PenTabBorder, path);
using (GraphicsPath path = GetTabOutline(tab, false, true))
{
Color startColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.StartColor;
Color endColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.EndColor;
LinearGradientMode gradientMode = DockPanel.Skin.AutoHideStripSkin.TabGradient.LinearGradientMode;
g.FillPath(new LinearGradientBrush(rectTabOrigin, startColor, endColor, gradientMode), path);
g.DrawPath(PenTabBorder, path);
}
// Set no rotate for drawing icon and text
Matrix matrixRotate = g.Transform;
g.Transform = MatrixIdentity;
// Draw the icon
Rectangle rectImage = rectTabOrigin;
rectImage.X += ImageGapLeft;
rectImage.Y += ImageGapTop;
int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom;
int imageWidth = ImageWidth;
if (imageHeight > ImageHeight)
imageWidth = ImageWidth * (imageHeight / ImageHeight);
rectImage.Height = imageHeight;
rectImage.Width = imageWidth;
rectImage = GetTransformedRectangle(dockState, rectImage);
if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
using (Matrix matrixRotate = g.Transform)
{
// The DockState is DockLeftAutoHide or DockRightAutoHide, so rotate the image 90 degrees to the right.
Rectangle rectTransform = RtlTransform(rectImage, dockState);
Point[] rotationPoints =
{
new Point(rectTransform.X + rectTransform.Width, rectTransform.Y),
new Point(rectTransform.X + rectTransform.Width, rectTransform.Y + rectTransform.Height),
new Point(rectTransform.X, rectTransform.Y)
};
g.Transform = MatrixIdentity;
using (Icon rotatedIcon = new Icon(((Form)content).Icon, 16, 16))
// Draw the icon
Rectangle rectImage = rectTabOrigin;
rectImage.X += ImageGapLeft;
rectImage.Y += ImageGapTop;
int imageHeight = rectTabOrigin.Height - ImageGapTop - ImageGapBottom;
int imageWidth = ImageWidth;
if (imageHeight > ImageHeight)
imageWidth = ImageWidth * (imageHeight / ImageHeight);
rectImage.Height = imageHeight;
rectImage.Width = imageWidth;
rectImage = GetTransformedRectangle(dockState, rectImage);
if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
{
g.DrawImage(rotatedIcon.ToBitmap(), rotationPoints);
// The DockState is DockLeftAutoHide or DockRightAutoHide, so rotate the image 90 degrees to the right.
Rectangle rectTransform = RtlTransform(rectImage, dockState);
Point[] rotationPoints =
{
new Point(rectTransform.X + rectTransform.Width, rectTransform.Y),
new Point(rectTransform.X + rectTransform.Width, rectTransform.Y + rectTransform.Height),
new Point(rectTransform.X, rectTransform.Y)
};
using (Icon rotatedIcon = new Icon(((Form)content).Icon, 16, 16))
{
g.DrawImage(rotatedIcon.ToBitmap(), rotationPoints);
}
}
else
{
// Draw the icon normally without any rotation.
g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState));
}
// Draw the text
Rectangle rectText = rectTabOrigin;
rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
rectText = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState);
Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor;
if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical);
else
g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal);
// Set rotate back
g.Transform = matrixRotate;
}
else
{
// Draw the icon normally without any rotation.
g.DrawIcon(((Form)content).Icon, RtlTransform(rectImage, dockState));
}
// Draw the text
Rectangle rectText = rectTabOrigin;
rectText.X += ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
rectText.Width -= ImageGapLeft + imageWidth + ImageGapRight + TextGapLeft;
rectText = RtlTransform(GetTransformedRectangle(dockState, rectText), dockState);
Color textColor = DockPanel.Skin.AutoHideStripSkin.TabGradient.TextColor;
if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabVertical);
else
g.DrawString(content.DockHandler.TabText, TextFont, new SolidBrush(textColor), rectText, StringFormatTabHorizontal);
// Set rotate back
g.Transform = matrixRotate;
}
private Rectangle GetLogicalTabStripRectangle(DockState dockState)
@@ -476,10 +479,12 @@ namespace WeifenLuo.WinFormsUI.Docking
pts[0].X = (float)rect.X + (float)rect.Width / 2;
pts[0].Y = (float)rect.Y + (float)rect.Height / 2;
Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState);
Matrix matrix = new Matrix();
matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
matrix.TransformPoints(pts);
using (var matrix = new Matrix())
{
matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
matrix.TransformPoints(pts);
}
return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F),
(int)(pts[0].Y - (float)rect.Width / 2 + .5F),

View File

@@ -492,10 +492,12 @@ namespace WeifenLuo.WinFormsUI.Docking
pts[0].X = (float)rect.X + (float)rect.Width / 2;
pts[0].Y = (float)rect.Y + (float)rect.Height / 2;
Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState);
Matrix matrix = new Matrix();
matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
matrix.TransformPoints(pts);
using (var matrix = new Matrix())
{
matrix.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
matrix.TransformPoints(pts);
}
return new Rectangle((int)(pts[0].X - (float)rect.Height / 2 + .5F),
(int)(pts[0].Y - (float)rect.Width / 2 + .5F),

View File

@@ -42,18 +42,18 @@ namespace WeifenLuo.WinFormsUI.Docking
case DockState.DockRightAutoHide:
case DockState.DockLeftAutoHide:
{
var path = new GraphicsPath();
path.AddRectangle(rect);
var brush = new PathGradientBrush(path)
using (var path = new GraphicsPath())
{
path.AddRectangle(rect);
using (var brush = new PathGradientBrush(path)
{
CenterColor = Color.FromArgb(0xFF, 204, 206, 219), SurroundColors = _verticalSurroundColors
})
{
CenterColor = Color.FromArgb(0xFF, 204, 206, 219),
SurroundColors = _verticalSurroundColors
};
e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y,
Measures.SplitterSize / 3, rect.Height);
path.Dispose();
brush.Dispose();
e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y,
Measures.SplitterSize / 3, rect.Height);
}
}
}
break;
case DockState.DockBottomAutoHide:

View File

@@ -77,19 +77,18 @@ namespace WeifenLuo.WinFormsUI.Docking
case DockStyle.Right:
case DockStyle.Left:
{
var path = new GraphicsPath();
path.AddRectangle(rect);
var brush = new PathGradientBrush(path)
using (var path = new GraphicsPath())
{
path.AddRectangle(rect);
using (var brush = new PathGradientBrush(path)
{
CenterColor = Color.FromArgb(0xFF, 204, 206, 219), SurroundColors = _verticalSurroundColors
})
{
CenterColor = Color.FromArgb(0xFF, 204, 206, 219),
SurroundColors = _verticalSurroundColors
};
e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y,
Measures.SplitterSize/3, rect.Height);
path.Dispose();
brush.Dispose();
e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y,
Measures.SplitterSize/3, rect.Height);
}
}
}
break;
case DockStyle.Bottom:

View File

@@ -29,19 +29,18 @@ namespace WeifenLuo.WinFormsUI.Docking
case DockAlignment.Right:
case DockAlignment.Left:
{
var path = new GraphicsPath();
path.AddRectangle(rect);
var brush = new PathGradientBrush(path)
using (var path = new GraphicsPath())
{
path.AddRectangle(rect);
using (var brush = new PathGradientBrush(path)
{
CenterColor = Color.FromArgb(0xFF, 204, 206, 219), SurroundColors = _verticalSurroundColors
})
{
CenterColor = Color.FromArgb(0xFF, 204, 206, 219),
SurroundColors = _verticalSurroundColors
};
e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y,
Measures.SplitterSize / 3, rect.Height);
path.Dispose();
brush.Dispose();
e.Graphics.FillRectangle(brush, rect.X + Measures.SplitterSize / 2 - 1, rect.Y,
Measures.SplitterSize / 3, rect.Height);
}
}
}
break;
case DockAlignment.Bottom:

View File

@@ -161,6 +161,7 @@ namespace WeifenLuo.WinFormsUI.Docking
{
path.Transform(matrix);
}
Region region = new Region(path);
SetDragForm(rect, region);
}
@@ -171,14 +172,29 @@ namespace WeifenLuo.WinFormsUI.Docking
{
DragForm.Bounds = rect;
if (rect == Rectangle.Empty)
{
if (DragForm.Region != null)
{
DragForm.Region.Dispose();
}
DragForm.Region = new Region(Rectangle.Empty);
}
else if (DragForm.Region != null)
{
DragForm.Region.Dispose();
DragForm.Region = null;
}
}
private void SetDragForm(Rectangle rect, Region region)
{
DragForm.Bounds = rect;
if (DragForm.Region != null)
{
DragForm.Region.Dispose();
}
DragForm.Region = region;
}
}

View File

@@ -281,6 +281,10 @@
<Content Include="Docking\Resources\DockIndicator_PanelTop_VS2012.bmp" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<UsingTask Condition=" '$(Configuration)' == 'Release' AND '$(OS)' == 'Windows_NT' AND Exists('..\gendarme\GendarmeMsBuild.dll')" AssemblyFile="..\gendarme\GendarmeMsBuild.dll" TaskName="GendarmeMsBuild.Gendarme" />
<Target Name="AfterBuild">
<Gendarme Condition=" '$(Configuration)' == 'Release' AND '$(OS)' == 'Windows_NT' AND Exists('..\gendarme\gendarme.exe')" GendarmeExeFilename="..\gendarme\gendarme.exe" Assemblies="$(TargetPath)" WarningsAsErrors="False" IntegrateWithVisualStudio="True" GendarmeIgnoreFilename="gendarme.ignore" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">