+ UIDataGridViewFooter:增加DataGridView页脚,可做统计显示

This commit is contained in:
Sunny 2021-04-20 23:30:23 +08:00
parent 118feaaddb
commit cbcf0b8dd1
8 changed files with 199 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -32,8 +32,10 @@
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
this.uiDataGridView1 = new Sunny.UI.UIDataGridView(); this.uiDataGridView1 = new Sunny.UI.UIDataGridView();
this.uiPagination1 = new Sunny.UI.UIPagination(); this.uiPagination1 = new Sunny.UI.UIPagination();
this.uiDataGridViewFooter1 = new Sunny.UI.UIDataGridViewFooter();
this.PagePanel.SuspendLayout(); this.PagePanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.uiDataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.uiDataGridView1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -41,6 +43,7 @@
// PagePanel // PagePanel
// //
this.PagePanel.Controls.Add(this.uiDataGridView1); this.PagePanel.Controls.Add(this.uiDataGridView1);
this.PagePanel.Controls.Add(this.uiDataGridViewFooter1);
this.PagePanel.Controls.Add(this.uiPagination1); this.PagePanel.Controls.Add(this.uiPagination1);
this.PagePanel.Size = new System.Drawing.Size(861, 415); this.PagePanel.Size = new System.Drawing.Size(861, 415);
// //
@ -59,7 +62,7 @@
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255))))); dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 12F); dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 12F);
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White; dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.uiDataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2; this.uiDataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
@ -80,37 +83,62 @@
this.uiDataGridView1.Location = new System.Drawing.Point(0, 0); this.uiDataGridView1.Location = new System.Drawing.Point(0, 0);
this.uiDataGridView1.MultiSelect = false; this.uiDataGridView1.MultiSelect = false;
this.uiDataGridView1.Name = "uiDataGridView1"; this.uiDataGridView1.Name = "uiDataGridView1";
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle4.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
dataGridViewCellStyle4.Font = new System.Drawing.Font("微软雅黑", 12F);
dataGridViewCellStyle4.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.uiDataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle4;
this.uiDataGridView1.RowHeadersVisible = false; this.uiDataGridView1.RowHeadersVisible = false;
dataGridViewCellStyle4.BackColor = System.Drawing.Color.White; dataGridViewCellStyle5.BackColor = System.Drawing.Color.White;
this.uiDataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle4; this.uiDataGridView1.RowsDefaultCellStyle = dataGridViewCellStyle5;
this.uiDataGridView1.RowTemplate.Height = 29; this.uiDataGridView1.RowTemplate.Height = 29;
this.uiDataGridView1.SelectedIndex = -1; this.uiDataGridView1.SelectedIndex = -1;
this.uiDataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.uiDataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.uiDataGridView1.ShowRect = false; this.uiDataGridView1.ShowRect = false;
this.uiDataGridView1.Size = new System.Drawing.Size(861, 380); this.uiDataGridView1.Size = new System.Drawing.Size(861, 345);
this.uiDataGridView1.TabIndex = 0; this.uiDataGridView1.TabIndex = 0;
// //
// uiPagination1 // uiPagination1
// //
this.uiPagination1.ActivePage = 50; this.uiPagination1.ActivePage = 20;
this.uiPagination1.CausesValidation = false; this.uiPagination1.CausesValidation = false;
this.uiPagination1.Dock = System.Windows.Forms.DockStyle.Bottom; this.uiPagination1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.uiPagination1.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiPagination1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiPagination1.Location = new System.Drawing.Point(0, 380); this.uiPagination1.Location = new System.Drawing.Point(0, 380);
this.uiPagination1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.uiPagination1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.uiPagination1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiPagination1.Name = "uiPagination1"; this.uiPagination1.Name = "uiPagination1";
this.uiPagination1.PagerCount = 11; this.uiPagination1.PagerCount = 11;
this.uiPagination1.PageSize = 50; this.uiPagination1.PageSize = 50;
this.uiPagination1.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None; this.uiPagination1.RadiusSides = Sunny.UI.UICornerRadiusSides.None;
this.uiPagination1.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.Top;
this.uiPagination1.Size = new System.Drawing.Size(861, 35); this.uiPagination1.Size = new System.Drawing.Size(861, 35);
this.uiPagination1.TabIndex = 1; this.uiPagination1.TabIndex = 1;
this.uiPagination1.Text = "uiDataGridPage1"; this.uiPagination1.Text = "uiDataGridPage1";
this.uiPagination1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
this.uiPagination1.TotalCount = 40000; this.uiPagination1.TotalCount = 40000;
this.uiPagination1.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.uiPagination1_PageChanged); this.uiPagination1.PageChanged += new Sunny.UI.UIPagination.OnPageChangeEventHandler(this.uiPagination1_PageChanged);
// //
// uiDataGridViewFooter1
//
this.uiDataGridViewFooter1.DataGridView = this.uiDataGridView1;
this.uiDataGridViewFooter1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.uiDataGridViewFooter1.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.uiDataGridViewFooter1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiDataGridViewFooter1.Location = new System.Drawing.Point(0, 345);
this.uiDataGridViewFooter1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiDataGridViewFooter1.Name = "uiDataGridViewFooter1";
this.uiDataGridViewFooter1.RadiusSides = Sunny.UI.UICornerRadiusSides.None;
this.uiDataGridViewFooter1.RectSides = System.Windows.Forms.ToolStripStatusLabelBorderSides.None;
this.uiDataGridViewFooter1.Size = new System.Drawing.Size(861, 35);
this.uiDataGridViewFooter1.TabIndex = 2;
this.uiDataGridViewFooter1.Text = "uiDataGridViewFooter1";
//
// FDataGridView // FDataGridView
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(861, 450); this.ClientSize = new System.Drawing.Size(861, 450);
this.Name = "FDataGridView"; this.Name = "FDataGridView";
@ -127,5 +155,6 @@
private UIDataGridView uiDataGridView1; private UIDataGridView uiDataGridView1;
private UIPagination uiPagination1; private UIPagination uiPagination1;
private UIDataGridViewFooter uiDataGridViewFooter1;
} }
} }

View File

@ -135,6 +135,7 @@ namespace Sunny.UI
private void VerticalScrollBar_ValueChanged(object sender, EventArgs e) private void VerticalScrollBar_ValueChanged(object sender, EventArgs e)
{ {
VBar.Value = FirstDisplayedScrollingRowIndex; VBar.Value = FirstDisplayedScrollingRowIndex;
VerticalScrollBarChanged?.Invoke(this, e);
} }
private void VBarValueChanged(object sender, EventArgs e) private void VBarValueChanged(object sender, EventArgs e)
@ -151,8 +152,13 @@ namespace Sunny.UI
{ {
HorizontalScrollBar.Value = HBar.Value; HorizontalScrollBar.Value = HBar.Value;
HorizontalScrollingOffset = HBar.Value; HorizontalScrollingOffset = HBar.Value;
HorizontalScrollBarChanged?.Invoke(this, e);
} }
public event EventHandler HorizontalScrollBarChanged;
public event EventHandler VerticalScrollBarChanged;
public void SetScrollInfo() public void SetScrollInfo()
{ {
if (VBar == null || HBar == null) if (VBar == null || HBar == null)

View File

@ -0,0 +1,157 @@
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2021 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@QQ.Com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UIDataGridViewFooter
* : DataGridView页脚
* : V3.0
* : 2021-04-20
*
* 2021-04-20: V3.0.3
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace Sunny.UI
{
[ToolboxItem(true)]
public class UIDataGridViewFooter : UIControl
{
public UIDataGridViewFooter()
{
SetStyleFlags(true, false, true);
Height = 35;
RadiusSides = UICornerRadiusSides.None;
RectSides = ToolStripStatusLabelBorderSides.None;
}
private UIDataGridView dgv;
public UIDataGridView DataGridView
{
get => dgv;
set
{
dgv = value;
if (dgv != null)
{
dgv.ColumnWidthChanged += Dgv_ColumnWidthChanged;
dgv.HorizontalScrollBarChanged += Dgv_HorizontalScrollBarChanged;
}
}
}
public void Clear()
{
dictionary.Clear();
Invalidate();
}
private readonly Dictionary<string, string> dictionary = new Dictionary<string, string>();
public string this[string name]
{
get => dictionary.ContainsKey(name) ? dictionary[name] : "";
set
{
if (dictionary.NotContainsKey(name))
dictionary.Add(name, value);
else
dictionary[name] = value;
Invalidate();
}
}
private void Dgv_HorizontalScrollBarChanged(object sender, EventArgs e)
{
Invalidate();
}
private void Dgv_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
{
Invalidate();
}
protected override void OnPaintFore(Graphics g, GraphicsPath path)
{
if (dgv.ColumnCount > 0 && dgv.RowCount > 0)
{
foreach (DataGridViewColumn column in dgv.Columns)
{
Rectangle rect = dgv.GetCellDisplayRectangle(column.Index, 0, false);
if (rect.Left == 0 && rect.Width == 0) continue;
string str = this[column.Name];
if (str.IsNullOrEmpty()) continue;
SizeF sf = g.MeasureString(str, Font);
if (rect.Left == 0 && rect.Width < column.Width)
{
g.DrawString(str, Font, Color.White, rect.Width - column.Width + (column.Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
}
else
{
g.DrawString(str, Font, Color.White, rect.Left + (column.Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
}
}
}
}
public override void SetStyleColor(UIBaseStyle uiColor)
{
base.SetStyleColor(uiColor);
if (uiColor.IsCustom()) return;
fillColor = uiColor.PlainColor;
Invalidate();
}
/// <summary>
/// 填充颜色,当值为背景色或透明色或空值则不填充
/// </summary>
[Description("填充颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color FillColor
{
get => fillColor;
set => SetFillColor(value);
}
/// <summary>
/// 边框颜色
/// </summary>
[Description("边框颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color RectColor
{
get => rectColor;
set => SetRectColor(value);
}
/// <summary>
/// 字体颜色
/// </summary>
[Description("字体颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "White")]
public override Color ForeColor
{
get => foreColor;
set => SetForeColor(value);
}
}
}