Added translucent form for splitters

This commit is contained in:
Robin 2015-09-19 15:30:09 +01:00
parent 12f227f542
commit 3c71944591
6 changed files with 105 additions and 7 deletions

View File

@ -124,6 +124,9 @@
<Compile Include="Forms\DarkMessageBox.Designer.cs">
<DependentUpon>DarkMessageBox.cs</DependentUpon>
</Compile>
<Compile Include="Forms\DarkTranslucentForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Icons\MenuIcons.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

View File

@ -9,6 +9,7 @@ namespace DarkUI
private Control _control;
private DarkSplitterType _splitterType;
private DarkTranslucentForm _overlayForm;
#endregion
@ -26,6 +27,7 @@ namespace DarkUI
{
_control = control;
_splitterType = splitterType;
_overlayForm = new DarkTranslucentForm(Color.Black);
switch (_splitterType)
{
@ -44,6 +46,41 @@ namespace DarkUI
#region Method Region
public void ShowOverlay()
{
_overlayForm.Show();
UpdateOverlay(new Point(0, 0));
}
public void HideOverlay()
{
_overlayForm.Hide();
}
public void UpdateOverlay(Point difference)
{
var bounds = _control.RectangleToScreen(Bounds);
switch (_splitterType)
{
case DarkSplitterType.Left:
bounds.Location = new Point(bounds.Location.X - difference.X, bounds.Location.Y);
break;
case DarkSplitterType.Right:
bounds.Location = new Point(bounds.Location.X - difference.X, bounds.Location.Y);
break;
case DarkSplitterType.Top:
bounds.Location = new Point(bounds.Location.X, bounds.Location.Y - difference.Y);
break;
case DarkSplitterType.Bottom:
bounds.Location = new Point(bounds.Location.X, bounds.Location.Y - difference.Y);
break;
}
_overlayForm.Location = bounds.Location;
_overlayForm.Size = bounds.Size;
}
public void Move(Point difference)
{
switch (_splitterType)

View File

@ -0,0 +1,30 @@
using System.Drawing;
using System.Windows.Forms;
namespace DarkUI
{
internal class DarkTranslucentForm : Form
{
#region Property Region
protected override bool ShowWithoutActivation
{
get { return true; }
}
#endregion
#region Constructor Region
public DarkTranslucentForm(Color backColor, double opacity = 0.6)
{
FormBorderStyle = FormBorderStyle.None;
ShowInTaskbar = false;
AllowTransparency = true;
Opacity = opacity;
BackColor = backColor;
}
#endregion
}
}

View File

@ -10,6 +10,7 @@ namespace DarkUI
private DarkDockPanel _dockPanel;
private Timer _dragTimer;
private bool _isDragging;
private Point _initialContact;
private DarkDockSplitter _activeSplitter;
@ -21,6 +22,10 @@ namespace DarkUI
public DarkDockResizeFilter(DarkDockPanel dockPanel)
{
_dockPanel = dockPanel;
_dragTimer = new Timer();
_dragTimer.Interval = 1;
_dragTimer.Tick += DragTimer_Tick;
}
#endregion
@ -100,22 +105,45 @@ namespace DarkUI
#endregion
#region Event Handler Region
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);
_activeSplitter.UpdateOverlay(difference);
}
#endregion
#region Method Region
private void StartDrag(DarkDockSplitter splitter)
{
Console.WriteLine("Start drag");
_activeSplitter = splitter;
Cursor.Current = _activeSplitter.ResizeCursor;
_initialContact = Cursor.Position;
_isDragging = true;
_activeSplitter.ShowOverlay();
_dragTimer.Start();
}
private void StopDrag()
{
Console.WriteLine("Stop drag");
_activeSplitter.HideOverlay();
_dragTimer.Stop();
var difference = new Point(_initialContact.X - Cursor.Position.X, _initialContact.Y - Cursor.Position.Y);
_activeSplitter.Move(difference);

View File

@ -4,12 +4,12 @@ using System.Runtime.InteropServices;
namespace DarkUI
{
public sealed class Native
internal sealed class Native
{
[DllImport("user32.dll")]
public static extern IntPtr WindowFromPoint(Point point);
internal static extern IntPtr WindowFromPoint(Point point);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
}
}

View File

@ -7,7 +7,7 @@ namespace DarkUI
/// Defined in winuser.h from Windows SDK v6.1
/// Documentation pulled from MSDN.
/// </summary>
public enum WM : uint
internal enum WM : uint
{
/// <summary>
/// The WM_NULL message performs no operation. An application sends the WM_NULL message if it wants to post a message that the recipient window will ignore.