|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2019 plexdata.de |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +using System; |
| 26 | +using System.Drawing; |
| 27 | +using System.Diagnostics; |
| 28 | +using System.Windows.Forms; |
| 29 | +using System.Windows.Forms.VisualStyles; |
| 30 | + |
| 31 | +namespace Plexdata.EnvironmentManager.Controls |
| 32 | +{ |
| 33 | + // Find a quite nice example of a splitter based on a TableLayoutPanel... |
| 34 | + // http://stackoverflow.com/questions/5033690/add-button-controls-to-splitcontainer-splitter/5046984#5046984 |
| 35 | + |
| 36 | + public class SplitContainerEx : SplitContainer |
| 37 | + { |
| 38 | + public SplitContainerEx() |
| 39 | + : base() |
| 40 | + { |
| 41 | + this.SetStyle(ControlStyles.DoubleBuffer, true); |
| 42 | + this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); |
| 43 | + this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); |
| 44 | + this.SetStyle(ControlStyles.UserPaint, true); |
| 45 | + this.SetStyle(ControlStyles.ResizeRedraw, true); |
| 46 | + |
| 47 | + base.TabStop = false; |
| 48 | + } |
| 49 | + |
| 50 | + protected override void OnKeyUp(KeyEventArgs args) |
| 51 | + { |
| 52 | + base.OnKeyUp(args); |
| 53 | + // Needed to disable painted focus rectangle... |
| 54 | + this.Refresh(); |
| 55 | + } |
| 56 | + |
| 57 | + protected override void OnPaint(PaintEventArgs args) |
| 58 | + { |
| 59 | + try |
| 60 | + { |
| 61 | + Size size = new Size(4, 40); // Gripper dimension... |
| 62 | + Rectangle rect = this.SplitterRectangle; |
| 63 | + VisualStyleRenderer renderer = null; |
| 64 | + |
| 65 | + if (this.Orientation == Orientation.Vertical) |
| 66 | + { |
| 67 | + rect.Y = (rect.Bottom - (rect.Top + size.Height)) / 2; |
| 68 | + rect.Height = size.Height; |
| 69 | + rect.Width = size.Width; |
| 70 | + rect.X += Math.Max((this.SplitterWidth - rect.Width) / 2, 0) - 1; |
| 71 | + |
| 72 | + if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.Gripper.Normal)) |
| 73 | + { |
| 74 | + renderer = new VisualStyleRenderer(VisualStyleElement.Rebar.Gripper.Normal); |
| 75 | + } |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + rect.X = (rect.Right - (rect.Left + size.Height)) / 2; |
| 80 | + rect.Height = size.Width; |
| 81 | + rect.Width = size.Height; |
| 82 | + rect.Y += Math.Max((this.SplitterWidth - rect.Height) / 2, 0) - 1; |
| 83 | + |
| 84 | + if (VisualStyleRenderer.IsElementDefined(VisualStyleElement.Rebar.GripperVertical.Normal)) |
| 85 | + { |
| 86 | + renderer = new VisualStyleRenderer(VisualStyleElement.Rebar.GripperVertical.Normal); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + if (renderer != null) |
| 91 | + { |
| 92 | + renderer.DrawBackground(args.Graphics, rect, args.ClipRectangle); |
| 93 | + } |
| 94 | + |
| 95 | + if (base.Focused && base.TabStop) |
| 96 | + { |
| 97 | + ControlPaint.DrawFocusRectangle(args.Graphics, |
| 98 | + Rectangle.Inflate(this.SplitterRectangle, -1, -1), |
| 99 | + this.ForeColor, this.BackColor); |
| 100 | + } |
| 101 | + } |
| 102 | + catch (Exception exception) |
| 103 | + { |
| 104 | + Debug.WriteLine(exception); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + protected override void OnDoubleClick(EventArgs args) |
| 109 | + { |
| 110 | + base.OnDoubleClick(args); |
| 111 | + if (this.Orientation == Orientation.Vertical) |
| 112 | + { |
| 113 | + this.SplitterDistance = this.ClientSize.Width / 2; |
| 114 | + } |
| 115 | + else |
| 116 | + { |
| 117 | + this.SplitterDistance = this.ClientSize.Height / 2; |
| 118 | + } |
| 119 | + this.Refresh(); |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | + |
0 commit comments