From 7770fc8d3da22234c3c25bf8e2b8ec7aa2d79190 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sat, 11 Jun 2022 12:54:26 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIDataGridView:=20=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=87=A0=E4=B8=AA=E5=8E=9F=E7=94=9F=E5=B1=9E=E6=80=A7=EF=BC=9A?= =?UTF-8?q?=20=E9=9A=90=E8=97=8F=20ShowRect,=20=E8=AE=BE=E7=BD=AE=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E5=B1=9E=E6=80=A7=EF=BC=9ABorderStyle=20=3D=20BorderS?= =?UTF-8?q?tyle.FixedSingle;=20=E9=9A=90=E8=97=8F=20ShowGridLine,=20?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8E=9F=E7=94=9F=E5=B1=9E=E6=80=A7=EF=BC=9A?= =?UTF-8?q?CellBorderStyle=20=3D=20DataGridViewCellBorderStyle.Single;=20?= =?UTF-8?q?=E9=9A=90=E8=97=8F=20RowHeight,=20=E7=94=A8=20SetRowHeight()=20?= =?UTF-8?q?=E4=BB=A3=E6=9B=BF=EF=BC=8C=E6=88=96=E8=AE=BE=E7=BD=AE=E5=8E=9F?= =?UTF-8?q?=E7=94=9F=E5=B1=9E=E6=80=A7=EF=BC=9AAutoSizeRowsMode=20=3D=20Da?= =?UTF-8?q?taGridViewAutoSizeRowsMode.None=EF=BC=8CRowTemplate.Height=20?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DropItem/UIComboDataGridViewItem.cs | 1 - SunnyUI/Controls/UIDataGridView.cs | 133 ++++++++---------- SunnyUI/Controls/UIDataGridViewFooter.cs | 5 +- SunnyUI/Forms/UIDataGridViewForm.Designer.cs | 2 - 4 files changed, 63 insertions(+), 78 deletions(-) diff --git a/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs b/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs index cfa486dd..f2bb7362 100644 --- a/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs +++ b/SunnyUI/Controls/DropItem/UIComboDataGridViewItem.cs @@ -182,7 +182,6 @@ namespace Sunny.UI dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; - this.dataGridView.RowHeight = 25; dataGridViewCellStyle5.BackColor = System.Drawing.Color.White; dataGridViewCellStyle5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(236)))), ((int)(((byte)(255))))); diff --git a/SunnyUI/Controls/UIDataGridView.cs b/SunnyUI/Controls/UIDataGridView.cs index 8bb14ad1..8145275a 100644 --- a/SunnyUI/Controls/UIDataGridView.cs +++ b/SunnyUI/Controls/UIDataGridView.cs @@ -31,6 +31,13 @@ * 2022-04-16: V3.1.3 增加滚动条的颜色设置 * 2022-04-26: V3.1.8 解决原生控件DataSource绑定List,并且List为空,出现”索引-1没有值“错误 * 2022-06-10: V3.1.9 不再判断DataSource绑定List为空,出现”索引-1没有值“用户自行判断 + * 2022-06-11: V3.1.9 隐藏 ShowRect, 设置原生属性: + * BorderStyle = BorderStyle.FixedSingle; + * 2022-06-11: V3.1.9 隐藏 ShowGridLine, 设置原生属性: + * CellBorderStyle = DataGridViewCellBorderStyle.Single; + * 2022-06-11: V3.1.9 隐藏 RowHeight, 用 SetRowHeight() 代替,或设置原生属性: + * AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None + * RowTemplate.Height 设置为高度 ******************************************************************************/ using System; @@ -103,23 +110,6 @@ namespace Sunny.UI HorizontalScrollBar.VisibleChanged += HorizontalScrollBar_VisibleChanged; } - //[ - // DefaultValue(null), - // RefreshProperties(RefreshProperties.Repaint), - // AttributeProvider(typeof(IListSource)), - // Description("提示 DataGridView 控件的数据源。") - //] - //public new object DataSource - //{ - // get => base.DataSource; - // set - // { - // //解决原生控件DataSource绑定List,并且List为空,出现”索引-1没有值“错误。 - // if (value is IList list && list.Count == 0) return; - // base.DataSource = value; - // } - //} - [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")] public bool ZoomScaleDisabled { get; set; } @@ -219,45 +209,32 @@ namespace Sunny.UI } } - [Description("行高"), Category("SunnyUI")] - [DefaultValue(23)] - public int RowHeight + //[Description("行高"), Category("SunnyUI")] + //[DefaultValue(23)] + [Browsable(false)] + [Obsolete("RowHeight 已过时,请用 SetRowHeight() 代替。", false)] + public int RowHeight { get; set; } + //{ + // get => RowTemplate.Height; + // set + // { + // AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; + // RowTemplate.Height = Math.Max(23, value); + // } + //} + + public void SetRowHeight(int height) { - get => RowTemplate.Height; - set - { - if (value > 23) - { - RowTemplate.Height = Math.Max(23, value); - RowTemplate.MinimumHeight = Math.Max(23, value); - AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; - } - } + AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; + RowTemplate.Height = height; } - /* - private bool showRowIndex; - - [Description("显示行号"), Category("SunnyUI")] - [DefaultValue(false)] - public bool ShowRowIndex + public void SetColumnHeadersHeight(int height) { - get => showRowIndex; - set - { - showRowIndex = value; - if (value) RowHeadersVisible = true; - Invalidate(); - } + ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; + ColumnHeadersHeight = height; } - protected override void OnRowStateChanged(int rowIndex, DataGridViewRowStateChangedEventArgs e) - { - base.OnRowStateChanged(rowIndex, e); - if (ShowRowIndex) e.Row.HeaderCell.Value = (e.Row.Index + 1).ToString(); - } - */ - private void HorizontalScrollBar_VisibleChanged(object sender, EventArgs e) { SetScrollInfo(); @@ -367,7 +344,7 @@ namespace Sunny.UI { base.OnPaint(e); - if (ShowRect) + if (BorderStyle == BorderStyle.FixedSingle) { Color color = RectColor; color = Enabled ? color : UIDisableColor.Fill; @@ -448,7 +425,7 @@ namespace Sunny.UI return; } - if (ShowRect) + if (BorderStyle == BorderStyle.FixedSingle) { VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 2; VBar.Top = 1; @@ -616,32 +593,42 @@ namespace Sunny.UI /// /// 是否显示边框 /// - [Description("是否显示边框"), Category("SunnyUI")] - [DefaultValue(true)] - public bool ShowRect - { - get => BorderStyle == BorderStyle.FixedSingle; - set - { - BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None; - Invalidate(); - } - } + //[Description("是否显示边框"), Category("SunnyUI")] + //[DefaultValue(true)] + [Browsable(false)] + [Obsolete("ShowRect 已过时,用原生属性:BorderStyle = BorderStyle.FixedSingle 代替。")] + public bool ShowRect { get; set; } + //{ + // get => BorderStyle == BorderStyle.FixedSingle; + // set + // { + // BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None; + // Invalidate(); + // } + //} /// /// 是否显示表格线 /// - [Description("是否显示表格线"), Category("SunnyUI")] - [DefaultValue(true)] - public bool ShowGridLine + //[Description("是否显示表格线"), Category("SunnyUI")] + //[DefaultValue(true)] + //[Browsable(false)] + [Obsolete("ShowGridLine 已过时,用原生属性:CellBorderStyle = DataGridViewCellBorderStyle.Single 代替。")] + public bool ShowGridLine { get; set; } + //{ + // get => CellBorderStyle == DataGridViewCellBorderStyle.Single; + // set + // { + // if (value && CellBorderStyle != DataGridViewCellBorderStyle.Single) + // CellBorderStyle = DataGridViewCellBorderStyle.Single; + // VBar.ShowLeftLine = CellBorderStyle == DataGridViewCellBorderStyle.Single; + // } + //} + + protected override void OnCellBorderStyleChanged(EventArgs e) { - get => CellBorderStyle == DataGridViewCellBorderStyle.Single; - set - { - if (value && CellBorderStyle != DataGridViewCellBorderStyle.Single) - CellBorderStyle = DataGridViewCellBorderStyle.Single; - VBar.ShowLeftLine = CellBorderStyle == DataGridViewCellBorderStyle.Single; - } + base.OnCellBorderStyleChanged(e); + VBar.ShowLeftLine = CellBorderStyle == DataGridViewCellBorderStyle.Single; } private Color _rectColor = UIColor.Blue; diff --git a/SunnyUI/Controls/UIDataGridViewFooter.cs b/SunnyUI/Controls/UIDataGridViewFooter.cs index d0a6c057..de22822b 100644 --- a/SunnyUI/Controls/UIDataGridViewFooter.cs +++ b/SunnyUI/Controls/UIDataGridViewFooter.cs @@ -98,11 +98,12 @@ namespace Sunny.UI { foreach (DataGridViewColumn column in dgv.Columns) { + bool ShowGridLine = dgv.CellBorderStyle == DataGridViewCellBorderStyle.Single; Rectangle rect = dgv.GetCellDisplayRectangle(column.Index, 0, false); - int minleft = dgv.ShowGridLine ? 1 : 0; + int minleft = ShowGridLine ? 1 : 0; if (rect.Left == minleft && rect.Width == 0) continue; - if (rect.Left >= minleft && dgv.ShowGridLine) + if (rect.Left >= minleft && ShowGridLine) { g.DrawLine(dgv.GridColor, rect.Left - minleft, 0, rect.Left - minleft, Height); g.DrawLine(dgv.GridColor, rect.Right - minleft, 0, rect.Right - minleft, Height); diff --git a/SunnyUI/Forms/UIDataGridViewForm.Designer.cs b/SunnyUI/Forms/UIDataGridViewForm.Designer.cs index fd66854c..d45719ea 100644 --- a/SunnyUI/Forms/UIDataGridViewForm.Designer.cs +++ b/SunnyUI/Forms/UIDataGridViewForm.Designer.cs @@ -80,12 +80,10 @@ dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.White; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.Grid.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; - this.Grid.RowHeight = 29; dataGridViewCellStyle5.BackColor = System.Drawing.Color.White; this.Grid.RowsDefaultCellStyle = dataGridViewCellStyle5; this.Grid.RowTemplate.Height = 29; this.Grid.SelectedIndex = -1; - this.Grid.ShowGridLine = true; this.Grid.Size = new System.Drawing.Size(1034, 511); this.Grid.TabIndex = 0; //