From 572b2601c0011e7a4451e45355e562dfbe8a7c35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=96=E6=B2=9B=20=E7=8E=8B?= <1016423262@qq.com>
Date: Sat, 28 Jun 2025 14:44:20 +0800
Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=A7=E4=BB=B6?=
=?UTF-8?q?=E5=9C=A8=E9=87=8D=E7=BB=98=E5=87=BD=E6=95=B0=E4=B8=AD=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9Region=E4=B8=8D=E6=96=AD=E9=87=8D=E7=BB=98=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
.../HZH_Controls/Controls/UCControlBase.cs | 63 +++++++++++++------
2 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/.gitignore b/.gitignore
index e829eba..4d496a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@
/HZH_Controls/Help
/HZH_Controls/HZH_Controls.sln.GhostDoc.xml
/HZH_Controls/.vs/
+/.vs/hzh_control/v17
diff --git a/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs b/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs
index b9d84a9..02749b7 100644
--- a/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs
+++ b/HZH_Controls/HZH_Controls/Controls/UCControlBase.cs
@@ -45,12 +45,19 @@ namespace HZH_Controls.Controls
/// The corner radius
///
private int _cornerRadius = 24;
-
-
///
- /// The is show rect
+ /// 标记上一次修改Region的时候bounds,防止不停重绘
///
- private bool _isShowRect = false;
+ private Rectangle bounds_reg;
+ ///
+ /// 标记上一次修改Region的时候radius,防止不停重绘
+ ///
+ private int radius_reg;
+
+ ///
+ /// The is show rect
+ ///
+ private bool _isShowRect = false;
///
/// The rect color
@@ -192,17 +199,20 @@ namespace HZH_Controls.Controls
{
if (this.Visible)
{
- if (this._isRadius)
- {
- this.SetWindowRegion();
- }
- else
+ if (NeedSetRegion())
{
- //关闭圆角后显示为原矩形
- GraphicsPath g = new GraphicsPath();
- g.AddRectangle(base.ClientRectangle);
- g.CloseFigure();
- base.Region = new Region(g);
+ if (this._isRadius)
+ {
+ this.SetWindowRegion();
+ }
+ else
+ {
+ //关闭圆角后显示为原矩形
+ GraphicsPath g = new GraphicsPath();
+ g.AddRectangle(base.ClientRectangle);
+ g.CloseFigure();
+ base.Region = new Region(g);
+ }
}
GraphicsPath graphicsPath = new GraphicsPath();
@@ -235,10 +245,27 @@ namespace HZH_Controls.Controls
base.OnPaint(e);
}
- ///
- /// Sets the window region.
- ///
- private void SetWindowRegion()
+ private bool NeedSetRegion()
+ {
+ if (this.bounds_reg != this.Bounds)
+ {
+ this.bounds_reg = this.Bounds;
+ this.radius_reg = this.ConerRadius;
+ return true;
+ }
+ if (this.radius_reg != this.ConerRadius)
+ {
+ this.bounds_reg = this.Bounds;
+ this.radius_reg = this.ConerRadius;
+ return true;
+ }
+ return false;
+ }
+
+ ///
+ /// Sets the window region.
+ ///
+ private void SetWindowRegion()
{
GraphicsPath path = new GraphicsPath();
Rectangle rect = new Rectangle(-1, -1, base.Width + 1, base.Height);
--
Gitee
From ebab231496cbfb0da6354431a43f267888f3d669 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=96=E6=B2=9B=20=E7=8E=8B?= <1016423262@qq.com>
Date: Sat, 28 Jun 2025 15:10:09 +0800
Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DUCKeyBorderAll?=
=?UTF-8?q?=E9=83=A8=E5=88=86=E7=89=B9=E6=AE=8A=E6=8C=89=E9=92=AE=E6=97=A0?=
=?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C=E7=9A=84bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controls/KeyBord/UCKeyBorderAll.cs | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/HZH_Controls/HZH_Controls/Controls/KeyBord/UCKeyBorderAll.cs b/HZH_Controls/HZH_Controls/Controls/KeyBord/UCKeyBorderAll.cs
index 0bccd2a..080024c 100644
--- a/HZH_Controls/HZH_Controls/Controls/KeyBord/UCKeyBorderAll.cs
+++ b/HZH_Controls/HZH_Controls/Controls/KeyBord/UCKeyBorderAll.cs
@@ -138,15 +138,15 @@ namespace HZH_Controls.Controls
if (EnterClick != null)
EnterClick(sender, e);
}
- else if (lbl.Text == "收起")
- {
- if (RetractClike != null)
- RetractClike(sender, e);
- }
- else
+ else if (lbl.Text == "收起")
+ {
+ if (RetractClike != null)
+ RetractClike(sender, e);
+ }
+ else
{
string Str = "{" + lbl.Text + "}";
- SendKeys.Send(lbl.Text);
+ SendKeys.Send(Str);
}
if (KeyClick != null)
KeyClick(sender, e);
--
Gitee
From 19cad9ba9f48d85f9232ee2ddc84b21d8169290d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=96=E6=B2=9B=20=E7=8E=8B?= <1016423262@qq.com>
Date: Sat, 28 Jun 2025 16:03:19 +0800
Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20WrapContents=3D?=
=?UTF-8?q?true=20=E6=97=B6=20UCDataGridView=20=E6=A8=AA=E5=90=91=E6=BB=9A?=
=?UTF-8?q?=E5=8A=A8=E6=9D=A1=E8=B7=B3=E5=9B=9E=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
通过 Win32 API 强制设置横向滚动位置,避免在控件 Focus 或布局刷新后被系统重置。
---
.../DataGridView/UCDataGridView.Designer.cs | 144 +++++++++---------
.../Controls/DataGridView/UCDataGridView.cs | 77 ++++++----
2 files changed, 120 insertions(+), 101 deletions(-)
diff --git a/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.Designer.cs b/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.Designer.cs
index 35f9cad..b3f1057 100644
--- a/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.Designer.cs
+++ b/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.Designer.cs
@@ -48,78 +48,78 @@ namespace HZH_Controls.Controls
///
private void InitializeComponent()
{
- this.panHead = new System.Windows.Forms.Panel();
- this.panColumns = new System.Windows.Forms.TableLayoutPanel();
- this.panHeadLeft = new System.Windows.Forms.Panel();
- this.panRow = new System.Windows.Forms.FlowLayoutPanel();
- this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
- this.panHead.SuspendLayout();
- this.SuspendLayout();
- //
- // panHead
- //
- this.panHead.Controls.Add(this.panColumns);
- this.panHead.Controls.Add(this.panHeadLeft);
- this.panHead.Controls.Add(this.ucSplitLine_H1);
- this.panHead.Location = new System.Drawing.Point(0, 0);
- this.panHead.Name = "panHead";
- this.panHead.Size = new System.Drawing.Size(1061, 40);
- this.panHead.TabIndex = 0;
- //
- // panColumns
- //
- this.panColumns.ColumnCount = 1;
- this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
- this.panColumns.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panColumns.Location = new System.Drawing.Point(0, 0);
- this.panColumns.Name = "panColumns";
- this.panColumns.RowCount = 1;
- this.panColumns.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
- this.panColumns.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
- this.panColumns.Size = new System.Drawing.Size(1061, 39);
- this.panColumns.TabIndex = 1;
- //
- // panHeadLeft
- //
- this.panHeadLeft.Dock = System.Windows.Forms.DockStyle.Left;
- this.panHeadLeft.Location = new System.Drawing.Point(0, 0);
- this.panHeadLeft.Name = "panHeadLeft";
- this.panHeadLeft.Size = new System.Drawing.Size(0, 39);
- this.panHeadLeft.TabIndex = 2;
- //
- // panRow
- //
- this.panRow.AutoScroll = true;
- this.panRow.Dock = System.Windows.Forms.DockStyle.Fill;
- this.panRow.Location = new System.Drawing.Point(0, 40);
- this.panRow.Name = "panRow";
- this.panRow.Size = new System.Drawing.Size(317, 225);
- this.panRow.TabIndex = 1;
- this.panRow.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panRow_Scroll);
- //
- // ucSplitLine_H1
- //
- this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
- this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Bottom;
- this.ucSplitLine_H1.Location = new System.Drawing.Point(0, 39);
- this.ucSplitLine_H1.Name = "ucSplitLine_H1";
- this.ucSplitLine_H1.Size = new System.Drawing.Size(1061, 1);
- this.ucSplitLine_H1.TabIndex = 0;
- this.ucSplitLine_H1.TabStop = false;
- //
- // UCDataGridView
- //
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
- this.BackColor = System.Drawing.Color.White;
- this.Controls.Add(this.panRow);
- this.Controls.Add(this.panHead);
- this.Name = "UCDataGridView";
- this.Padding = new System.Windows.Forms.Padding(0, 40, 0, 0);
- this.Size = new System.Drawing.Size(317, 265);
- this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.UCDataGridView_Scroll);
- this.SizeChanged += new System.EventHandler(this.UCDataGridView_SizeChanged);
- this.panHead.ResumeLayout(false);
- this.ResumeLayout(false);
+ this.panHead = new System.Windows.Forms.Panel();
+ this.panColumns = new System.Windows.Forms.TableLayoutPanel();
+ this.panHeadLeft = new System.Windows.Forms.Panel();
+ this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
+ this.panRow = new System.Windows.Forms.FlowLayoutPanel();
+ this.panHead.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // panHead
+ //
+ this.panHead.Controls.Add(this.panColumns);
+ this.panHead.Controls.Add(this.panHeadLeft);
+ this.panHead.Controls.Add(this.ucSplitLine_H1);
+ this.panHead.Location = new System.Drawing.Point(0, 0);
+ this.panHead.Name = "panHead";
+ this.panHead.Size = new System.Drawing.Size(1061, 40);
+ this.panHead.TabIndex = 0;
+ //
+ // panColumns
+ //
+ this.panColumns.ColumnCount = 1;
+ this.panColumns.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.panColumns.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.panColumns.Location = new System.Drawing.Point(0, 0);
+ this.panColumns.Name = "panColumns";
+ this.panColumns.RowCount = 1;
+ this.panColumns.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.panColumns.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
+ this.panColumns.Size = new System.Drawing.Size(1061, 39);
+ this.panColumns.TabIndex = 1;
+ //
+ // panHeadLeft
+ //
+ this.panHeadLeft.Dock = System.Windows.Forms.DockStyle.Left;
+ this.panHeadLeft.Location = new System.Drawing.Point(0, 0);
+ this.panHeadLeft.Name = "panHeadLeft";
+ this.panHeadLeft.Size = new System.Drawing.Size(0, 39);
+ this.panHeadLeft.TabIndex = 2;
+ //
+ // ucSplitLine_H1
+ //
+ this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
+ this.ucSplitLine_H1.Dock = System.Windows.Forms.DockStyle.Bottom;
+ this.ucSplitLine_H1.Location = new System.Drawing.Point(0, 39);
+ this.ucSplitLine_H1.Name = "ucSplitLine_H1";
+ this.ucSplitLine_H1.Size = new System.Drawing.Size(1061, 1);
+ this.ucSplitLine_H1.TabIndex = 0;
+ this.ucSplitLine_H1.TabStop = false;
+ //
+ // panRow
+ //
+ this.panRow.AutoScroll = true;
+ this.panRow.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.panRow.Location = new System.Drawing.Point(0, 40);
+ this.panRow.Name = "panRow";
+ this.panRow.Size = new System.Drawing.Size(317, 225);
+ this.panRow.TabIndex = 1;
+ this.panRow.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panRow_Scroll);
+ //
+ // UCDataGridView
+ //
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
+ this.BackColor = System.Drawing.Color.White;
+ this.Controls.Add(this.panRow);
+ this.Controls.Add(this.panHead);
+ this.Name = "UCDataGridView";
+ this.Padding = new System.Windows.Forms.Padding(0, 40, 0, 0);
+ this.Size = new System.Drawing.Size(317, 265);
+ this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.UCDataGridView_Scroll);
+ this.SizeChanged += new System.EventHandler(this.UCDataGridView_SizeChanged);
+ this.panHead.ResumeLayout(false);
+ this.ResumeLayout(false);
}
diff --git a/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.cs b/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.cs
index 5bdee5b..122ed86 100644
--- a/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.cs
+++ b/HZH_Controls/HZH_Controls/Controls/DataGridView/UCDataGridView.cs
@@ -32,17 +32,22 @@ namespace HZH_Controls.Controls
///
public partial class UCDataGridView : UserControl
{
- #region 属性
- ///
- /// The m head pading left
- ///
- private int m_headPadingLeft = 0;
-
- ///
- /// Gets or sets the head pading left.
- ///
- /// The head pading left.
- [Description("标题左侧间距"), Category("自定义")]
+ #region 属性
+ ///
+ /// 只在主线程使用的变量,记录了上一次focus之前的x位置
+ ///
+ private int pre_x;
+
+ ///
+ /// The m head pading left
+ ///
+ private int m_headPadingLeft = 0;
+
+ ///
+ /// Gets or sets the head pading left.
+ ///
+ /// The head pading left.
+ [Description("标题左侧间距"), Category("自定义")]
public int HeadPadingLeft
{
get { return m_headPadingLeft; }
@@ -384,10 +389,11 @@ namespace HZH_Controls.Controls
///
[Description("标题点击事件"), Category("自定义")]
public EventHandler HeadColumnClickEvent;
- ///
- /// Occurs when [item click].
- ///
- [Description("项点击事件"), Category("自定义")]
+
+ ///
+ /// Occurs when [item click].
+ ///
+ [Description("项点击事件"), Category("自定义")]
public event DataGridViewEventHandler ItemClick;
///
/// Occurs when [source changed].
@@ -615,8 +621,14 @@ namespace HZH_Controls.Controls
Control rowControl = (row as Control);
rowControl.Width = panHead.Width;
- row.RowHeight = m_rowHeight;
- row.CellClick += (a, b) => { this.FindForm().ActiveControl = this; rowControl.Focus(); SetSelectRow(rowControl, b); };
+ row.RowHeight = m_rowHeight;
+ row.CellClick += (a, b) => {
+ this.FindForm().ActiveControl = this;
+ pre_x= this.panRow.AutoScrollPosition.X;
+ rowControl.Focus();
+
+ SetSelectRow(rowControl, b);
+ };
row.CheckBoxChangeEvent += (a, b) => { SetSelectRow(rowControl, b); };
row.RowCustomEvent += (a, b) => { if (RowCustomEvent != null) { RowCustomEvent(a, b); } };
row.SourceChanged += RowSourceChanged;
@@ -746,7 +758,9 @@ namespace HZH_Controls.Controls
{
try
{
- ControlHelper.FreezeControl(this, true);
+ int currentX = -pre_x; // 保留当前横向滚动值(注意是负数)
+
+ ControlHelper.FreezeControl(this, true);
if (item == null)
return;
if (item.Visible == false)
@@ -764,19 +778,24 @@ namespace HZH_Controls.Controls
if (this.panRow.Controls.Count > 0)
{
- if (item.Location.Y < 0)
- {
- this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.Controls[this.panRow.Controls.Count - 1].Location.Y) + item.Location.Y);
- }
- else if (item.Location.Y + m_rowHeight > this.panRow.Height)
- {
- this.panRow.AutoScrollPosition = new Point(0, Math.Abs(this.panRow.AutoScrollPosition.Y) + item.Location.Y - this.panRow.Height + m_rowHeight);
- }
- }
- }
+ if (item.Location.Y < 0)
+ {
+ int newY = Math.Abs(this.panRow.Controls[this.panRow.Controls.Count - 1].Location.Y) + item.Location.Y;
+ this.panRow.AutoScrollPosition = new Point(currentX, newY);
+ }
+ else if (item.Location.Y + m_rowHeight > this.panRow.Height)
+ {
+ int newY = Math.Abs(this.panRow.AutoScrollPosition.Y) + item.Location.Y - this.panRow.Height + m_rowHeight;
+ this.panRow.AutoScrollPosition = new Point(currentX, newY);
+ }
+
+
+ }
+ }
+ ControlHelper.SetHScrollValue(this.panRow.Handle, currentX);
- if (ItemClick != null)
+ if (ItemClick != null)
{
ItemClick(item, e);
}
--
Gitee