Commit f30bda0f kwwwvagaa

优化表格显示 支持横向滚动条

1 个父辈 68681cd7
......@@ -48,11 +48,13 @@ namespace HZH_Controls.Controls
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
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.Panel();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.ucSplitLine_H1 = new HZH_Controls.Controls.UCSplitLine_H();
this.panHead.SuspendLayout();
this.SuspendLayout();
//
......@@ -61,7 +63,6 @@ namespace HZH_Controls.Controls
this.panHead.Controls.Add(this.panColumns);
this.panHead.Controls.Add(this.panHeadLeft);
this.panHead.Controls.Add(this.ucSplitLine_H1);
this.panHead.Dock = System.Windows.Forms.DockStyle.Top;
this.panHead.Location = new System.Drawing.Point(0, 0);
this.panHead.Name = "panHead";
this.panHead.Size = new System.Drawing.Size(1061, 40);
......@@ -88,6 +89,18 @@ namespace HZH_Controls.Controls
this.panHeadLeft.Size = new System.Drawing.Size(0, 39);
this.panHeadLeft.TabIndex = 2;
//
// panRow
//
this.panRow.Location = new System.Drawing.Point(0, 40);
this.panRow.Name = "panRow";
this.panRow.Size = new System.Drawing.Size(1061, 525);
this.panRow.TabIndex = 1;
//
// timer1
//
this.timer1.Interval = 1;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// ucSplitLine_H1
//
this.ucSplitLine_H1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(232)))), ((int)(((byte)(232)))), ((int)(((byte)(232)))));
......@@ -98,24 +111,17 @@ namespace HZH_Controls.Controls
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(1061, 525);
this.panRow.TabIndex = 1;
//
// UCDataGridView
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.AutoScroll = true;
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.panRow);
this.Controls.Add(this.panHead);
this.Controls.Add(this.panRow);
this.Name = "UCDataGridView";
this.Size = new System.Drawing.Size(1061, 565);
this.Scroll += new System.Windows.Forms.ScrollEventHandler(this.UCDataGridView_Scroll);
this.SizeChanged += new System.EventHandler(this.UCDataGridView_SizeChanged);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.UCDataGridView_Paint);
this.panHead.ResumeLayout(false);
this.ResumeLayout(false);
......@@ -143,6 +149,7 @@ namespace HZH_Controls.Controls
/// The pan head left
/// </summary>
private System.Windows.Forms.Panel panHeadLeft;
private System.Windows.Forms.Timer timer1;
}
}
......@@ -96,8 +96,21 @@ namespace HZH_Controls.Controls
get { return m_isShowHead; }
set
{
if (m_isShowHead != value)
{
m_isShowHead = value;
panHead.Visible = value;
if (value)
{
this.panRow.Location = new Point(0, panHead.Height);
this.panRow.Height = this.panRow.Height - panHead.Height;
}
else
{
this.panRow.Location = new Point(0, 0);
this.panRow.Height = this.panRow.Height + panHead.Height;
}
}
}
}
/// <summary>
......@@ -391,12 +404,48 @@ namespace HZH_Controls.Controls
{ return; }
ControlHelper.FreezeControl(this.panHead, true);
this.panRow.Controls.Clear();
this.panColumns.Controls.Clear();
this.panColumns.ColumnStyles.Clear();
if (m_columns != null && m_columns.Count() > 0)
{
int _width = 0;
m_columns.ForEach(p =>
{
if (p.WidthType == SizeType.Absolute)
{
_width += p.Width;
}
else if (p.WidthType == SizeType.Percent)
{
_width += (int)((p.Width / 100f) * this.Width);
}
});
if (m_isShowCheckBox)
_width += 30;
if (_width > this.Width)
{
this.panRow.Width = _width;
this.panHead.Width = _width;
}
else
{
if (m_columns.Any(p => p.WidthType == SizeType.AutoSize))
{
this.panRow.Width = this.Width;
this.panHead.Width = this.Width;
}
else
{
this.panRow.Width = _width;
this.panHead.Width = _width;
}
}
m_columns.FindAll(p => p.WidthType == SizeType.Absolute);
m_columns.FindAll(p => p.WidthType == SizeType.Percent);
int intColumnsCount = m_columns.Count();
if (m_isShowCheckBox)
{
......@@ -469,6 +518,7 @@ namespace HZH_Controls.Controls
try
{
ControlHelper.FreezeControl(this, true);
panHead.Location = new Point(0, 0);
Rows = new List<IDataGridViewRow>();
if (m_columns == null || m_columns.Count <= 0)
return;
......@@ -549,6 +599,8 @@ namespace HZH_Controls.Controls
}
}
this.panRow.Height = intSourceCount * RowHeight;
}
else
{
......@@ -710,5 +762,34 @@ namespace HZH_Controls.Controls
#endregion
private void UCDataGridView_SizeChanged(object sender, EventArgs e)
{
//LoadColumns();
//ReloadSource();
}
private void UCDataGridView_Scroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
panHead.Location = new Point(0, this.VerticalScroll.Value + this.panRow.Location.Y - panHead.Height - 2);
timer1.Enabled = true;
scrollIndex = 0;
}
}
private void UCDataGridView_Paint(object sender, PaintEventArgs e)
{
}
int scrollIndex = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (scrollIndex > 1000)
timer1.Enabled = false;
panHead.Location = new Point(0, this.VerticalScroll.Value + this.panRow.Location.Y - panHead.Height - 2);
scrollIndex++;
}
}
}
......@@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
......@@ -155,7 +155,7 @@ namespace HZH_Controls.Controls
});
}
};
this.ucDGVChild.AutoScroll = false;
}
/// <summary>
......
......@@ -33,10 +33,10 @@
//
// ucDataGridView1
//
this.ucDataGridView1.AutoScroll = true;
this.ucDataGridView1.BackColor = System.Drawing.Color.White;
this.ucDataGridView1.Columns = null;
this.ucDataGridView1.DataSource = null;
this.ucDataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.ucDataGridView1.HeadFont = new System.Drawing.Font("微软雅黑", 12F);
this.ucDataGridView1.HeadHeight = 40;
this.ucDataGridView1.HeadPadingLeft = 0;
......@@ -47,13 +47,13 @@
this.ucDataGridView1.Name = "ucDataGridView1";
this.ucDataGridView1.RowHeight = 41;
this.ucDataGridView1.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow);
this.ucDataGridView1.Size = new System.Drawing.Size(739, 599);
this.ucDataGridView1.Size = new System.Drawing.Size(722, 583);
this.ucDataGridView1.TabIndex = 4;
//
// UCTestGridTable
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.ucDataGridView1);
this.Name = "UCTestGridTable";
this.Size = new System.Drawing.Size(739, 599);
......
......@@ -25,8 +25,8 @@ namespace Test.UC
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "ID", HeadText = "编号", Width = 70, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Name", HeadText = "姓名", Width = 100, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Age", HeadText = "年龄", Width = 500, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Birthday", HeadText = "生日", Width = 500, WidthType = SizeType.Absolute, Format = (a) => { return ((DateTime)a).ToString("yyyy-MM-dd"); } });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Sex", HeadText = "性别", Width = 500, WidthType = SizeType.Absolute, Format = (a) => { return ((int)a) == 0 ? "女" : "男"; } });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Birthday", HeadText = "生日", Width = 150, WidthType = SizeType.Absolute, Format = (a) => { return ((DateTime)a).ToString("yyyy-MM-dd"); } });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Sex", HeadText = "性别", Width = 50, WidthType = SizeType.Absolute, Format = (a) => { return ((int)a) == 0 ? "女" : "男"; } });
this.ucDataGridView1.Columns = lstCulumns;
this.ucDataGridView1.IsShowCheckBox = true;
List<object> lstSource = new List<object>();
......
......@@ -40,6 +40,5 @@ namespace Test.UC
e.Graphics.FillPath(new SolidBrush(Color.FromArgb(50, Color.White)), uc.BorderPath);
}
}
}
}
......@@ -33,10 +33,10 @@
//
// ucDataGridView1
//
this.ucDataGridView1.AutoScroll = true;
this.ucDataGridView1.BackColor = System.Drawing.Color.White;
this.ucDataGridView1.Columns = null;
this.ucDataGridView1.DataSource = null;
this.ucDataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.ucDataGridView1.HeadFont = new System.Drawing.Font("微软雅黑", 12F);
this.ucDataGridView1.HeadHeight = 40;
this.ucDataGridView1.HeadPadingLeft = 24;
......@@ -47,13 +47,13 @@
this.ucDataGridView1.Name = "ucDataGridView1";
this.ucDataGridView1.RowHeight = 41;
this.ucDataGridView1.RowType = typeof(HZH_Controls.Controls.UCDataGridViewRow);
this.ucDataGridView1.Size = new System.Drawing.Size(825, 674);
this.ucDataGridView1.Size = new System.Drawing.Size(807, 655);
this.ucDataGridView1.TabIndex = 5;
//
// UCTestTreeGridTable
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.ucDataGridView1);
this.Name = "UCTestTreeGridTable";
this.Size = new System.Drawing.Size(825, 674);
......
......@@ -24,10 +24,10 @@ namespace Test.UC
this.ucDataGridView1.RowType = typeof(UCDataGridViewTreeRow);
List<DataGridViewColumnEntity> lstCulumns = new List<DataGridViewColumnEntity>();
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "ID", HeadText = "编号", Width = 70, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Name", HeadText = "姓名", Width = 50, WidthType = SizeType.Percent });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Age", HeadText = "年龄", Width = 50, WidthType = SizeType.Percent });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Birthday", HeadText = "生日", Width = 50, WidthType = SizeType.Percent, Format = (a) => { return ((DateTime)a).ToString("yyyy-MM-dd"); } });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Sex", HeadText = "性别", Width = 50, WidthType = SizeType.Percent, Format = (a) => { return ((int)a) == 0 ? "女" : "男"; } });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Name", HeadText = "姓名", Width = 150, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Age", HeadText = "年龄", Width = 150, WidthType = SizeType.Absolute });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Birthday", HeadText = "生日", Width = 150, WidthType = SizeType.Absolute, Format = (a) => { return ((DateTime)a).ToString("yyyy-MM-dd"); } });
lstCulumns.Add(new DataGridViewColumnEntity() { DataField = "Sex", HeadText = "性别", Width = 150, WidthType = SizeType.Absolute, Format = (a) => { return ((int)a) == 0 ? "女" : "男"; } });
this.ucDataGridView1.Columns = lstCulumns;
this.ucDataGridView1.IsShowCheckBox = true;
List<object> lstSource = new List<object>();
......@@ -59,7 +59,7 @@ namespace Test.UC
{
ID = i.ToString(),
Age = 3 * i,
Name = intCount + "——" + i,
Name = "姓名——" + i,
Birthday = DateTime.Now.AddYears(-10),
Sex = i % 2
};
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!