diff --git a/DarkUI/DarkUI.csproj b/DarkUI/DarkUI.csproj
index 5cc190d..aaa2a5e 100644
--- a/DarkUI/DarkUI.csproj
+++ b/DarkUI/DarkUI.csproj
@@ -108,6 +108,7 @@
+
Form
diff --git a/DarkUI/Docking/DarkDockRegion.cs b/DarkUI/Docking/DarkDockRegion.cs
index 7b26095..c91a72a 100644
--- a/DarkUI/Docking/DarkDockRegion.cs
+++ b/DarkUI/Docking/DarkDockRegion.cs
@@ -86,7 +86,6 @@ namespace DarkUI
var newGroup = new DarkDockGroup(DockPanel, this);
_groups.Add(newGroup);
Controls.Add(newGroup);
- newGroup.BringToFront();
PositionGroups();
@@ -121,10 +120,21 @@ namespace DarkUI
}
if (_groups.Count == 1)
+ {
_groups[0].Dock = DockStyle.Fill;
+ }
else if (_groups.Count > 1)
+ {
foreach (var group in _groups)
- group.Dock = dockStyle;
+ {
+ group.SendToBack();
+
+ if (_groups.IsLast(group))
+ group.Dock = dockStyle;
+ else
+ group.Dock = DockStyle.Fill;
+ }
+ }
}
private void BuildProperties()
diff --git a/DarkUI/Docking/Items/DarkDockSplitter.cs b/DarkUI/Docking/Items/DarkDockSplitter.cs
index 7696e03..f913fad 100644
--- a/DarkUI/Docking/Items/DarkDockSplitter.cs
+++ b/DarkUI/Docking/Items/DarkDockSplitter.cs
@@ -44,6 +44,25 @@ namespace DarkUI
#region Method Region
+ public void Move(Point difference)
+ {
+ switch (_splitterType)
+ {
+ case DarkSplitterType.Left:
+ _control.Width += difference.X;
+ break;
+ case DarkSplitterType.Right:
+ _control.Width -= difference.X;
+ break;
+ case DarkSplitterType.Top:
+ _control.Height += difference.Y;
+ break;
+ case DarkSplitterType.Bottom:
+ _control.Height -= difference.Y;
+ break;
+ }
+ }
+
public void UpdateBounds()
{
switch (_splitterType)
diff --git a/DarkUI/Extensions/BitmapExtensions.cs b/DarkUI/Extensions/BitmapExtensions.cs
index 82f68d6..77eef6b 100644
--- a/DarkUI/Extensions/BitmapExtensions.cs
+++ b/DarkUI/Extensions/BitmapExtensions.cs
@@ -2,9 +2,9 @@
namespace DarkUI
{
- public static class BitmapExtensions
+ internal static class BitmapExtensions
{
- public static Bitmap SetColor(this Bitmap bitmap, Color color)
+ internal static Bitmap SetColor(this Bitmap bitmap, Color color)
{
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
for (int i = 0; i < bitmap.Width; i++)
@@ -19,7 +19,7 @@ namespace DarkUI
return newBitmap;
}
- public static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
+ internal static Bitmap ChangeColor(this Bitmap bitmap, Color oldColor, Color newColor)
{
var newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
for (int i = 0; i < bitmap.Width; i++)
diff --git a/DarkUI/Extensions/IEnumerableExtensions.cs b/DarkUI/Extensions/IEnumerableExtensions.cs
new file mode 100644
index 0000000..2855a3a
--- /dev/null
+++ b/DarkUI/Extensions/IEnumerableExtensions.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace DarkUI
+{
+ internal static class IEnumerableExtensions
+ {
+ internal static bool IsLast(this IEnumerable items, T item)
+ {
+ var last = items.LastOrDefault();
+ if (last == null)
+ return false;
+ return item.Equals(last); // OR Object.ReferenceEquals(last, item)
+ }
+
+ internal static bool IsFirst(this IEnumerable items, T item)
+ {
+ var first = items.FirstOrDefault();
+ if (first == null)
+ return false;
+ return item.Equals(first);
+ }
+
+ internal static bool IsFirstOrLast(this IEnumerable items, T item)
+ {
+ return items.IsFirst(item) || items.IsLast(item);
+ }
+ }
+}
diff --git a/DarkUI/Win32/DarkDockResizeFilter.cs b/DarkUI/Win32/DarkDockResizeFilter.cs
index 9ad7c9e..b324e3d 100644
--- a/DarkUI/Win32/DarkDockResizeFilter.cs
+++ b/DarkUI/Win32/DarkDockResizeFilter.cs
@@ -1,4 +1,5 @@
-using System.Drawing;
+using System;
+using System.Drawing;
using System.Windows.Forms;
namespace DarkUI
@@ -10,6 +11,7 @@ namespace DarkUI
private DarkDockPanel _dockPanel;
private bool _isDragging;
+ private Point _initialContact;
private DarkDockSplitter _activeSplitter;
#endregion
@@ -33,16 +35,13 @@ namespace DarkUI
m.Msg == (int)WM.RBUTTONDOWN || m.Msg == (int)WM.RBUTTONUP || m.Msg == (int)WM.RBUTTONDBLCLK))
return false;
- // Exit out early if we're simply releasing a drag over the area
+ // Exit out early if we're simply releasing a non-splitter drag over the area
if (m.Msg == (int)WM.LBUTTONUP && !_isDragging)
return false;
// Force cursor if already dragging.
- ForceDraggingCursor();
-
- // Stop all events from going through if we're dragging a splitter.
if (_isDragging)
- return true;
+ Cursor.Current = _activeSplitter.ResizeCursor;
// Return out early if we're dragging something that's not a splitter.
if (m.Msg == (int)WM.MOUSEMOVE && !_isDragging && _dockPanel.MouseButtonState != MouseButtons.None)
@@ -65,17 +64,26 @@ namespace DarkUI
// Start drag.
if (m.Msg == (int)WM.LBUTTONDOWN)
{
+ foreach (var splitter in _dockPanel.Splitters)
+ {
+ if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
+ {
+ StartDrag(splitter);
+ return true;
+ }
+ }
}
// Stop drag.
if (m.Msg == (int)WM.LBUTTONUP)
{
+ if (_isDragging)
+ {
+ StopDrag();
+ return true;
+ }
}
- // Stop events passing through if we just started to drag something
- if (_isDragging)
- return true;
-
// Stop events passing through if we're hovering over a splitter
foreach (var splitter in _dockPanel.Splitters)
{
@@ -83,6 +91,10 @@ namespace DarkUI
return true;
}
+ // Stop all events from going through if we're dragging a splitter.
+ if (_isDragging)
+ return true;
+
return false;
}
@@ -90,19 +102,25 @@ namespace DarkUI
#region Method Region
- private void ForceDraggingCursor()
+ private void StartDrag(DarkDockSplitter splitter)
{
- if (_isDragging)
- {
- SetCursor(_activeSplitter.ResizeCursor);
- return;
- }
+ Console.WriteLine("Start drag");
+
+ _activeSplitter = splitter;
+ Cursor.Current = _activeSplitter.ResizeCursor;
+
+ _initialContact = Cursor.Position;
+ _isDragging = true;
}
- private void ResetCursor()
+ private void StopDrag()
{
- Cursor.Current = Cursors.Default;
- CheckCursor();
+ Console.WriteLine("Stop drag");
+
+ var difference = new Point(_initialContact.X - Cursor.Position.X, _initialContact.Y - Cursor.Position.Y);
+ _activeSplitter.Move(difference);
+
+ _isDragging = false;
}
private void CheckCursor()
@@ -114,15 +132,16 @@ namespace DarkUI
{
if (splitter.Bounds.Contains(_dockPanel.PointToClient(Cursor.Position)))
{
- SetCursor(splitter.ResizeCursor);
+ Cursor.Current = splitter.ResizeCursor;
return;
}
}
}
- private void SetCursor(Cursor cursor)
+ private void ResetCursor()
{
- Cursor.Current = cursor;
+ Cursor.Current = Cursors.Default;
+ CheckCursor();
}
#endregion
diff --git a/Example/Forms/MainForm.cs b/Example/Forms/MainForm.cs
index 5672673..b6316ed 100644
--- a/Example/Forms/MainForm.cs
+++ b/Example/Forms/MainForm.cs
@@ -43,6 +43,11 @@ namespace Example
DockPanel.AddContent(_dockLayers);
DockPanel.AddContent(_dockHistory);
+ // Add 3 dummy documents to the main document area of the dock panel
+ DockPanel.AddContent(new DockDocument { DockText = "Document 1" });
+ DockPanel.AddContent(new DockDocument { DockText = "Document 2" });
+ DockPanel.AddContent(new DockDocument { DockText = "Document 3" });
+
// Show the tool windows as visible in the 'Window' menu
mnuProject.Checked = true;
mnuProperties.Checked = true;