1 using System;
2 using System.Diagnostics;
3 using System.Drawing;
4 using System.Drawing.Drawing2D;
5 using System.Windows.Forms;
6 using WeifenLuo.WinFormsUI.Docking;
7 
8 namespace WeifenLuo.WinFormsUI.ThemeVS2012
9 {
10     public class VS2012WindowSplitterControl : SplitterBase
11     {
12         private readonly SolidBrush _horizontalBrush;
13         private readonly SolidBrush _backgroundBrush;
14         private PathGradientBrush _foregroundBrush;
15         private readonly Color[] _verticalSurroundColors;
16         private readonly ISplitterHost _host;
17 
VS2012WindowSplitterControl(ISplitterHost host)18         public VS2012WindowSplitterControl(ISplitterHost host)
19         {
20             _host = host;
21             _horizontalBrush = host.DockPanel.Theme.PaintingService.GetBrush(host.DockPanel.Theme.ColorPalette.TabSelectedInactive.Background);
22             _backgroundBrush = host.DockPanel.Theme.PaintingService.GetBrush(host.DockPanel.Theme.ColorPalette.MainWindowActive.Background);
23             _verticalSurroundColors = new[]
24             {
25                 host.DockPanel.Theme.ColorPalette.MainWindowActive.Background
26             };
27         }
28 
OnSizeChanged(EventArgs e)29         protected override void OnSizeChanged(EventArgs e)
30         {
31             base.OnSizeChanged(e);
32             Rectangle rect = ClientRectangle;
33             if (rect.Width <= 0 || rect.Height <= 0)
34                 return;
35 
36             if (Dock != DockStyle.Left && Dock != DockStyle.Right)
37                 return;
38 
39             _foregroundBrush?.Dispose();
40             using (var path = new GraphicsPath())
41             {
42                 path.AddRectangle(rect);
43                 _foregroundBrush = new PathGradientBrush(path)
44                 {
45                     CenterColor = _horizontalBrush.Color,
46                     SurroundColors = _verticalSurroundColors
47                 };
48             }
49         }
50 
Dispose(bool disposing)51         protected override void Dispose(bool disposing)
52         {
53             if (!IsDisposed && disposing)
54             {
55                 _foregroundBrush?.Dispose();
56             }
57 
58             base.Dispose(disposing);
59         }
60 
61         protected override int SplitterSize
62         {
63             get { return _host.IsDockWindow ? _host.DockPanel.Theme.Measures.SplitterSize : _host.DockPanel.Theme.Measures.AutoHideSplitterSize; }
64         }
65 
StartDrag()66         protected override void StartDrag()
67         {
68             _host.DockPanel.BeginDrag(_host, _host.DragControl.RectangleToScreen(Bounds));
69         }
70 
OnPaint(PaintEventArgs e)71         protected override void OnPaint(PaintEventArgs e)
72         {
73             base.OnPaint(e);
74 
75             Rectangle rect = ClientRectangle;
76 
77             if (rect.Width <= 0 || rect.Height <= 0)
78                 return;
79 
80             if (_host.IsDockWindow)
81             {
82                 switch (Dock)
83                 {
84                     case DockStyle.Right:
85                     case DockStyle.Left:
86                         {
87                             Debug.Assert(SplitterSize == rect.Width);
88                             e.Graphics.FillRectangle(_backgroundBrush, rect);
89                             e.Graphics.FillRectangle(_foregroundBrush, rect.X + SplitterSize / 2 - 1, rect.Y,
90                                                         SplitterSize / 3, rect.Height);
91                         }
92                         break;
93                     case DockStyle.Bottom:
94                     case DockStyle.Top:
95                         {
96                             Debug.Assert(SplitterSize == rect.Height);
97                             e.Graphics.FillRectangle(_horizontalBrush, rect);
98                         }
99                         break;
100                 }
101 
102                 return;
103             }
104 
105             switch (_host.DockState)
106             {
107                 case DockState.DockRightAutoHide:
108                 case DockState.DockLeftAutoHide:
109                     {
110                         Debug.Assert(SplitterSize == rect.Width);
111                         e.Graphics.FillRectangle(_backgroundBrush, rect);
112                     }
113                     break;
114                 case DockState.DockBottomAutoHide:
115                 case DockState.DockTopAutoHide:
116                     {
117                         Debug.Assert(SplitterSize == rect.Height);
118                         e.Graphics.FillRectangle(_horizontalBrush, rect);
119                     }
120                     break;
121             }
122         }
123     }
124 
125 }
126