* UIDataGridView: 恢复几个原生属性:

隐藏 ShowRect, 设置原生属性:BorderStyle = BorderStyle.FixedSingle;
隐藏 ShowGridLine, 设置原生属性:CellBorderStyle = DataGridViewCellBorderStyle.Single;
隐藏 RowHeight, 用 SetRowHeight() 代替,或设置原生属性:AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None,RowTemplate.Height 设置为高度
This commit is contained in:
Sunny 2022-06-11 12:54:26 +08:00
parent f02080876e
commit 7770fc8d3d
4 changed files with 63 additions and 78 deletions

View File

@ -182,7 +182,6 @@ namespace Sunny.UI
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dataGridView.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
this.dataGridView.RowHeight = 25;
dataGridViewCellStyle5.BackColor = System.Drawing.Color.White; dataGridViewCellStyle5.BackColor = System.Drawing.Color.White;
dataGridViewCellStyle5.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48))))); 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))))); dataGridViewCellStyle5.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(236)))), ((int)(((byte)(255)))));

View File

@ -31,6 +31,13 @@
* 2022-04-16: V3.1.3 * 2022-04-16: V3.1.3
* 2022-04-26: V3.1.8 DataSource绑定ListList为空-1 * 2022-04-26: V3.1.8 DataSource绑定ListList为空-1
* 2022-06-10: V3.1.9 DataSource绑定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; using System;
@ -103,23 +110,6 @@ namespace Sunny.UI
HorizontalScrollBar.VisibleChanged += HorizontalScrollBar_VisibleChanged; 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("禁止控件跟随窗体缩放")] [DefaultValue(false), Category("SunnyUI"), Description("禁止控件跟随窗体缩放")]
public bool ZoomScaleDisabled { get; set; } public bool ZoomScaleDisabled { get; set; }
@ -219,45 +209,32 @@ namespace Sunny.UI
} }
} }
[Description("行高"), Category("SunnyUI")] //[Description("行高"), Category("SunnyUI")]
[DefaultValue(23)] //[DefaultValue(23)]
public int RowHeight [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; AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
set RowTemplate.Height = height;
{
if (value > 23)
{
RowTemplate.Height = Math.Max(23, value);
RowTemplate.MinimumHeight = Math.Max(23, value);
AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
}
}
} }
/* public void SetColumnHeadersHeight(int height)
private bool showRowIndex;
[Description("显示行号"), Category("SunnyUI")]
[DefaultValue(false)]
public bool ShowRowIndex
{ {
get => showRowIndex; ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
set ColumnHeadersHeight = height;
{
showRowIndex = value;
if (value) RowHeadersVisible = true;
Invalidate();
}
} }
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) private void HorizontalScrollBar_VisibleChanged(object sender, EventArgs e)
{ {
SetScrollInfo(); SetScrollInfo();
@ -367,7 +344,7 @@ namespace Sunny.UI
{ {
base.OnPaint(e); base.OnPaint(e);
if (ShowRect) if (BorderStyle == BorderStyle.FixedSingle)
{ {
Color color = RectColor; Color color = RectColor;
color = Enabled ? color : UIDisableColor.Fill; color = Enabled ? color : UIDisableColor.Fill;
@ -448,7 +425,7 @@ namespace Sunny.UI
return; return;
} }
if (ShowRect) if (BorderStyle == BorderStyle.FixedSingle)
{ {
VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 2; VBar.Left = Width - ScrollBarInfo.VerticalScrollBarWidth() - 2;
VBar.Top = 1; VBar.Top = 1;
@ -616,32 +593,42 @@ namespace Sunny.UI
/// <summary> /// <summary>
/// 是否显示边框 /// 是否显示边框
/// </summary> /// </summary>
[Description("是否显示边框"), Category("SunnyUI")] //[Description("是否显示边框"), Category("SunnyUI")]
[DefaultValue(true)] //[DefaultValue(true)]
public bool ShowRect [Browsable(false)]
{ [Obsolete("ShowRect 已过时用原生属性BorderStyle = BorderStyle.FixedSingle 代替。")]
get => BorderStyle == BorderStyle.FixedSingle; public bool ShowRect { get; set; }
set //{
{ // get => BorderStyle == BorderStyle.FixedSingle;
BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None; // set
Invalidate(); // {
} // BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None;
} // Invalidate();
// }
//}
/// <summary> /// <summary>
/// 是否显示表格线 /// 是否显示表格线
/// </summary> /// </summary>
[Description("是否显示表格线"), Category("SunnyUI")] //[Description("是否显示表格线"), Category("SunnyUI")]
[DefaultValue(true)] //[DefaultValue(true)]
public bool ShowGridLine //[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; base.OnCellBorderStyleChanged(e);
set VBar.ShowLeftLine = CellBorderStyle == DataGridViewCellBorderStyle.Single;
{
if (value && CellBorderStyle != DataGridViewCellBorderStyle.Single)
CellBorderStyle = DataGridViewCellBorderStyle.Single;
VBar.ShowLeftLine = CellBorderStyle == DataGridViewCellBorderStyle.Single;
}
} }
private Color _rectColor = UIColor.Blue; private Color _rectColor = UIColor.Blue;

View File

@ -98,11 +98,12 @@ namespace Sunny.UI
{ {
foreach (DataGridViewColumn column in dgv.Columns) foreach (DataGridViewColumn column in dgv.Columns)
{ {
bool ShowGridLine = dgv.CellBorderStyle == DataGridViewCellBorderStyle.Single;
Rectangle rect = dgv.GetCellDisplayRectangle(column.Index, 0, false); 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 && 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.Left - minleft, 0, rect.Left - minleft, Height);
g.DrawLine(dgv.GridColor, rect.Right - minleft, 0, rect.Right - minleft, Height); g.DrawLine(dgv.GridColor, rect.Right - minleft, 0, rect.Right - minleft, Height);

View File

@ -80,12 +80,10 @@
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.White; dataGridViewCellStyle4.SelectionForeColor = System.Drawing.Color.White;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.Grid.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; this.Grid.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
this.Grid.RowHeight = 29;
dataGridViewCellStyle5.BackColor = System.Drawing.Color.White; dataGridViewCellStyle5.BackColor = System.Drawing.Color.White;
this.Grid.RowsDefaultCellStyle = dataGridViewCellStyle5; this.Grid.RowsDefaultCellStyle = dataGridViewCellStyle5;
this.Grid.RowTemplate.Height = 29; this.Grid.RowTemplate.Height = 29;
this.Grid.SelectedIndex = -1; this.Grid.SelectedIndex = -1;
this.Grid.ShowGridLine = true;
this.Grid.Size = new System.Drawing.Size(1034, 511); this.Grid.Size = new System.Drawing.Size(1034, 511);
this.Grid.TabIndex = 0; this.Grid.TabIndex = 0;
// //