From 27d38dae6ad34f4a1214c82a1cf09f71ce2093b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=98=E6=B0=94=E5=B0=8F=E6=B5=A9?= <1298758589@qq.com> Date: Tue, 25 Mar 2025 06:36:25 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BE=20=E4=BF=AE=E5=A4=8D=20Splitter=20?= =?UTF-8?q?Lazy=20=E4=B8=8D=E7=94=9F=E6=95=88=20*=20=E4=BF=AE=E5=A4=8Dspli?= =?UTF-8?q?tter=E6=8E=A7=E4=BB=B6collapsepanel=E4=B8=BAnone=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=B8=8B=EF=BC=8Clazy=E4=B8=BAfalse=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dlazy=E4=B8=BAfalse=E6=97=B6=EF=BC=8Cissp=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Demo/Controls/Splitter.Designer.cs | 16 ++++--- src/AntdUI/Controls/Splitter.cs | 54 ++++++++++++---------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/example/Demo/Controls/Splitter.Designer.cs b/example/Demo/Controls/Splitter.Designer.cs index f7c59ad4..7cc6a657 100644 --- a/example/Demo/Controls/Splitter.Designer.cs +++ b/example/Demo/Controls/Splitter.Designer.cs @@ -101,6 +101,7 @@ namespace Demo.Controls // splitter1 // splitter1.Dock = DockStyle.Fill; + splitter1.Lazy = false; splitter1.Location = new Point(3, 3); splitter1.Name = "splitter1"; // @@ -112,8 +113,9 @@ namespace Demo.Controls // splitter1.Panel2.Controls.Add(label2); splitter1.Size = new Size(610, 249); - splitter1.SplitterDistance = 290; - splitter1.SplitterWidth = 2; + splitter1.SplitterDistance = 218; + splitter1.SplitterSize = 50; + splitter1.SplitterWidth = 8; splitter1.TabIndex = 1; // // label1 @@ -121,7 +123,7 @@ namespace Demo.Controls label1.Dock = DockStyle.Fill; label1.Location = new Point(0, 0); label1.Name = "label1"; - label1.Size = new Size(290, 249); + label1.Size = new Size(218, 249); label1.TabIndex = 0; label1.Text = "First"; label1.TextAlign = ContentAlignment.MiddleCenter; @@ -131,7 +133,7 @@ namespace Demo.Controls label2.Dock = DockStyle.Fill; label2.Location = new Point(0, 0); label2.Name = "label2"; - label2.Size = new Size(318, 249); + label2.Size = new Size(384, 249); label2.TabIndex = 0; label2.Text = "Second"; label2.TextAlign = ContentAlignment.MiddleCenter; @@ -153,7 +155,7 @@ namespace Demo.Controls splitter2.Panel2.Controls.Add(label4); splitter2.Panel2MinSize = 0; splitter2.Size = new Size(610, 250); - splitter2.SplitterDistance = 290; + splitter2.SplitterDistance = 273; splitter2.SplitterSize = 80; splitter2.SplitterWidth = 10; splitter2.TabIndex = 2; @@ -163,7 +165,7 @@ namespace Demo.Controls label3.Dock = DockStyle.Fill; label3.Location = new Point(0, 0); label3.Name = "label3"; - label3.Size = new Size(290, 250); + label3.Size = new Size(273, 250); label3.TabIndex = 0; label3.Text = "First"; label3.TextAlign = ContentAlignment.MiddleCenter; @@ -173,7 +175,7 @@ namespace Demo.Controls label4.Dock = DockStyle.Fill; label4.Location = new Point(0, 0); label4.Name = "label4"; - label4.Size = new Size(310, 250); + label4.Size = new Size(327, 250); label4.TabIndex = 0; label4.Text = "Second"; label4.TextAlign = ContentAlignment.MiddleCenter; diff --git a/src/AntdUI/Controls/Splitter.cs b/src/AntdUI/Controls/Splitter.cs index d146bf01..da35248f 100644 --- a/src/AntdUI/Controls/Splitter.cs +++ b/src/AntdUI/Controls/Splitter.cs @@ -406,13 +406,13 @@ namespace AntdUI Point initialMousePoint; protected override void OnMouseDown(MouseEventArgs e) { - if (_collapsePanel == ADCollapsePanel.None) - { - base.OnMouseDown(e); - return; - } + //if (_collapsePanel == ADCollapsePanel.None) + //{ + // base.OnMouseDown(e); + // return; + //} Rectangle rect = SplitterRectangle, rect_arrow = ArrowRect(rect); - if (rect_arrow.Contains(e.Location)) _MouseState = true;//点位在箭头矩形内 + if (_collapsePanel != ADCollapsePanel.None && rect_arrow.Contains(e.Location)) _MouseState = true;//点位在箭头矩形内 else if (!SplitPanelState) _MouseState = null; else if (rect.Contains(e.Location)) { @@ -425,7 +425,7 @@ namespace AntdUI protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); - if (_collapsePanel == ADCollapsePanel.None) return; + //if (_collapsePanel == ADCollapsePanel.None) return; SetCursor(CursorType.Default); m_bIsArrowRegion = false; Invalidate(); @@ -433,17 +433,17 @@ namespace AntdUI protected override void OnMouseMove(MouseEventArgs e) { - if (_collapsePanel == ADCollapsePanel.None) - { - base.OnMouseMove(e); - return; - } + //if (_collapsePanel == ADCollapsePanel.None) + //{ + // base.OnMouseMove(e); + // return; + //} //如果鼠标的左键没有按下,重置鼠标状态 if (e.Button != MouseButtons.Left) _MouseState = null; //鼠标在Arrow矩形里,并且不是在拖动 Rectangle rect = SplitterRectangle, rect_arrow = ArrowRect(rect); - if (rect_arrow.Contains(e.Location) && _MouseState != false) + if (_collapsePanel != ADCollapsePanel.None && rect_arrow.Contains(e.Location) && _MouseState != false) { SetCursor(CursorType.Hand); m_bIsArrowRegion = true; @@ -463,14 +463,18 @@ namespace AntdUI return; } //正在拖动分隔栏 - if (_MouseState == false && !IsSplitterFixed) SetCursor(Orientation == Orientation.Horizontal ? CursorType.HSplit : CursorType.VSplit); - else SetCursor(CursorType.Default); - if (Lazy) base.OnMouseMove(e); - else + if (_MouseState == false && !IsSplitterFixed) { - SplitMove(e.X, e.Y); - initialMousePoint = e.Location; + SetCursor(Orientation == Orientation.Horizontal ? CursorType.HSplit : CursorType.VSplit); + if(!Lazy) + { + SplitMove(e.X, e.Y); + initialMousePoint = e.Location; + return; + } } + else SetCursor(CursorType.Default); + base.OnMouseMove(e); } private void SplitMove(int x, int y) @@ -511,14 +515,14 @@ namespace AntdUI protected override void OnMouseUp(MouseEventArgs e) { - if (_collapsePanel == ADCollapsePanel.None) - { - base.OnMouseUp(e); - return; - } + //if (_collapsePanel == ADCollapsePanel.None) + //{ + // base.OnMouseUp(e); + // return; + //} if (Lazy) base.OnMouseUp(e); Invalidate(); - if (_MouseState == true && e.Button == MouseButtons.Left && ArrowRect(SplitterRectangle).Contains(e.Location)) + if (_collapsePanel != ADCollapsePanel.None && _MouseState == true && e.Button == MouseButtons.Left && ArrowRect(SplitterRectangle).Contains(e.Location)) { SplitPanelState = !_splitPanelState; SplitPanelStateChanged?.Invoke(this, new BoolEventArgs(SplitPanelState));