Fixed PointToScreen issues with splitters

This commit is contained in:
Robin 2015-09-19 17:56:37 +01:00
parent 99b405be39
commit a463149ad7
3 changed files with 27 additions and 35 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
@ -169,13 +170,13 @@ namespace DarkUI
switch (DockArea) switch (DockArea)
{ {
case DarkDockArea.Left: case DarkDockArea.Left:
_splitter = new DarkDockSplitter(this, DarkSplitterType.Right); _splitter = new DarkDockSplitter(DockPanel, this, DarkSplitterType.Right);
break; break;
case DarkDockArea.Right: case DarkDockArea.Right:
_splitter = new DarkDockSplitter(this, DarkSplitterType.Left); _splitter = new DarkDockSplitter(DockPanel, this, DarkSplitterType.Left);
break; break;
case DarkDockArea.Bottom: case DarkDockArea.Bottom:
_splitter = new DarkDockSplitter(this, DarkSplitterType.Top); _splitter = new DarkDockSplitter(DockPanel, this, DarkSplitterType.Top);
break; break;
default: default:
return; return;
@ -193,7 +194,7 @@ namespace DarkUI
base.OnLayout(e); base.OnLayout(e);
if (_splitter != null) if (_splitter != null)
_splitter.UpdateBounds(DockPanel); _splitter.UpdateBounds();
} }
#endregion #endregion

View File

@ -1,4 +1,5 @@
using System.Drawing; using System;
using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace DarkUI namespace DarkUI
@ -7,6 +8,7 @@ namespace DarkUI
{ {
#region Field Region #region Field Region
private Control _parentControl;
private Control _control; private Control _control;
private DarkSplitterType _splitterType; private DarkSplitterType _splitterType;
private DarkTranslucentForm _overlayForm; private DarkTranslucentForm _overlayForm;
@ -23,8 +25,9 @@ namespace DarkUI
#region Constructor Region #region Constructor Region
public DarkDockSplitter(Control control, DarkSplitterType splitterType) public DarkDockSplitter(Control parentControl, Control control, DarkSplitterType splitterType)
{ {
_parentControl = parentControl;
_control = control; _control = control;
_splitterType = splitterType; _splitterType = splitterType;
_overlayForm = new DarkTranslucentForm(Color.Black); _overlayForm = new DarkTranslucentForm(Color.Black);
@ -91,23 +94,22 @@ namespace DarkUI
_control.Width += difference.X; _control.Width += difference.X;
break; break;
case DarkSplitterType.Right: case DarkSplitterType.Right:
_control.Width += difference.X; _control.Width -= difference.X;
break; break;
case DarkSplitterType.Top: case DarkSplitterType.Top:
_control.Height -= difference.Y; _control.Height += difference.Y;
break; break;
case DarkSplitterType.Bottom: case DarkSplitterType.Bottom:
_control.Height -= difference.Y; _control.Height -= difference.Y;
break; break;
} }
UpdateBounds();
} }
public void UpdateBounds(Control rootControl) public void UpdateBounds()
{ {
if (rootControl == null) var bounds = _parentControl.RectangleToScreen(_control.Bounds);
rootControl = _control;
var bounds = rootControl.RectangleToScreen(_control.Bounds);
switch (_splitterType) switch (_splitterType)
{ {

View File

@ -40,6 +40,16 @@ namespace DarkUI
m.Msg == (int)WM.RBUTTONDOWN || m.Msg == (int)WM.RBUTTONUP || m.Msg == (int)WM.RBUTTONDBLCLK)) m.Msg == (int)WM.RBUTTONDOWN || m.Msg == (int)WM.RBUTTONUP || m.Msg == (int)WM.RBUTTONDBLCLK))
return false; return false;
// Stop drag.
if (m.Msg == (int)WM.LBUTTONUP)
{
if (_isDragging)
{
StopDrag();
return true;
}
}
// Exit out early if we're simply releasing a non-splitter 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) if (m.Msg == (int)WM.LBUTTONUP && !_isDragging)
return false; return false;
@ -77,16 +87,6 @@ namespace DarkUI
} }
} }
// Stop drag.
if (m.Msg == (int)WM.LBUTTONUP)
{
if (_isDragging)
{
StopDrag();
return true;
}
}
// Stop events passing through if we're hovering over a splitter // Stop events passing through if we're hovering over a splitter
if (HotSplitter() != null) if (HotSplitter() != null)
return true; return true;
@ -104,17 +104,6 @@ namespace DarkUI
private void DragTimer_Tick(object sender, EventArgs e) private void DragTimer_Tick(object sender, EventArgs e)
{ {
if (_dockPanel.MouseButtonState != MouseButtons.Left)
_isDragging = false;
if (!_isDragging)
{
_activeSplitter.HideOverlay();
_dragTimer.Stop();
ResetCursor();
return;
}
var difference = new Point(_initialContact.X - Cursor.Position.X, _initialContact.Y - Cursor.Position.Y); var difference = new Point(_initialContact.X - Cursor.Position.X, _initialContact.Y - Cursor.Position.Y);
_activeSplitter.UpdateOverlay(difference); _activeSplitter.UpdateOverlay(difference);
} }