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; //