(十二)c#Winform自定义控件-分页控件
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492 idkey=6e08741ef16fe53bf0314c1c9e336c4f626047943a8b76bac062361bab6b4f8d">
目录
https://www.cnblogs.com/bfyx/p/11364884.html
准备工作
当一个列表加载数据过多时,比如datagridview,如果数据过多,则可能超出内存,相应慢等问题,此时需要用到翻页控件。
设计思路,对翻页控件定义接口,基类实现,如果所列的翻页控件样式或功能无法满足你的需求的话,你只需要基类翻页控件基类或者实现接口即可。
定义接口是因为后面的一些列表控件内置了翻页控件,为了达到兼容扩展,所有使用了接口定义约束。
开始
首先需要一个分页事件用到的委托,偷懒,只写了一个
[Serializable]
[ComVisible(true)]
public delegate void PageControlEventHandler(object currentSource);
我们先定义一个接口IPageControl
public interface IPageControl
{
/// <summary>
/// 数据源改变时发生
/// </summary>
event PageControlEventHandler ShowSourceChanged;
/// <summary>
/// 数据源
/// </summary>
List<object> DataSource { get; set; }
/// <summary>
/// 显示数量
/// </summary>
int PageSize { get; set; }
/// <summary>
/// 开始下标
/// </summary>
int StartIndex { get; set; }
/// <summary>
/// 第一页
/// </summary>
void FirstPage();
/// <summary>
/// 前一页
/// </summary>
void PreviousPage();
/// <summary>
/// 下一页
/// </summary>
void NextPage();
/// <summary>
/// 最后一页
/// </summary>
void EndPage();
/// <summary>
/// 重新加载
/// </summary>
void Reload();
/// <summary>
/// 获取当前页数据
/// </summary>
/// <returns></returns>
List<object> GetCurrentSource();
/// <summary>
/// 总页数
/// </summary>
int PageCount { get; set; }
/// <summary>
/// 当前页
/// </summary>
int PageIndex { get; set; }
}
然后定义一个分页基类控件,添加一个用户控件,命名UCPagerControlBase,并实现接口IPageControl
看下属性
/// <summary>
/// 总页数
/// </summary>
public virtual int PageCount
{
get;
set;
}
private int m_pageIndex = ;
/// <summary>
/// 当前页码
/// </summary>
public virtual int PageIndex
{
get { return m_pageIndex; }
set { m_pageIndex = value; }
}
/// <summary>
/// 关联的数据源
/// </summary>
public virtual List<object> DataSource { get; set; }
public virtual event PageControlEventHandler ShowSourceChanged;
private int m_pageSize = ;
/// <summary>
/// 每页显示数量
/// </summary>
[Description("每页显示数量"), Category("自定义")]
public virtual int PageSize
{
get { return m_pageSize; }
set { m_pageSize = value; }
}
private int startIndex = ;
/// <summary>
/// 开始的下标
/// </summary>
[Description("开始的下标"), Category("自定义")]
public virtual int StartIndex
{
get { return startIndex; }
set
{
startIndex = value;
if (startIndex <= )
startIndex = ;
}
}
然后定义虚函数,并做一些默认实现
/// <summary>
/// 第一页
/// </summary>
public virtual void FirstPage()
{
if (DataSource == null)
return;
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 上一页
/// </summary>
public virtual void PreviousPage()
{
if (DataSource == null)
return;
if (startIndex == )
return;
startIndex -= m_pageSize;
if (startIndex < )
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 下一页
/// </summary>
public virtual void NextPage()
{
if (DataSource == null)
return;
if (startIndex + m_pageSize >= DataSource.Count)
{
return;
}
startIndex += m_pageSize;
if (startIndex < )
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 最后一页
/// </summary>
public virtual void EndPage()
{
if (DataSource == null)
return;
startIndex = DataSource.Count - m_pageSize;
if (startIndex < )
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 刷新数据
/// </summary>
public virtual void Reload()
{
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 获取当前页数据
/// </summary>
/// <returns></returns>
public virtual List<object> GetCurrentSource()
{
if (DataSource == null)
return null;
int intShowCount = m_pageSize;
if (intShowCount + startIndex > DataSource.Count)
intShowCount = DataSource.Count - startIndex;
object[] objs = new object[intShowCount];
DataSource.CopyTo(startIndex, objs, , intShowCount);
var lst = objs.ToList(); bool blnLeft = false;
bool blnRight = false;
if (lst.Count > )
{
if (DataSource.IndexOf(lst[]) > )
{
blnLeft = true;
}
else
{
blnLeft = false;
}
if (DataSource.IndexOf(lst[lst.Count - ]) >= DataSource.Count - )
{
blnRight = false;
}
else
{
blnRight = true;
}
}
ShowBtn(blnLeft, blnRight);
return lst;
} /// <summary>
/// 控制按钮显示
/// </summary>
/// <param name="blnLeftBtn">是否显示上一页,第一页</param>
/// <param name="blnRightBtn">是否显示下一页,最后一页</param>
protected virtual void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{ }
如此基类就完成了,看下完整代码
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:UCPagerControlBase.cs
// 创建日期:2019-08-15 16:00:41
// 功能描述:PageControl
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace HZH_Controls.Controls
{
[ToolboxItem(false)]
public class UCPagerControlBase : UserControl, IPageControl
{
#region 构造
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// UCPagerControlBase
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Name = "UCPagerControlBase";
this.Size = new System.Drawing.Size(, );
this.Load += new System.EventHandler(this.UCPagerControlBase_Load);
this.ResumeLayout(false); } #endregion
#endregion
/// <summary>
/// 总页数
/// </summary>
public virtual int PageCount
{
get;
set;
}
private int m_pageIndex = ;
/// <summary>
/// 当前页码
/// </summary>
public virtual int PageIndex
{
get { return m_pageIndex; }
set { m_pageIndex = value; }
}
/// <summary>
/// 关联的数据源
/// </summary>
public virtual List<object> DataSource { get; set; }
public virtual event PageControlEventHandler ShowSourceChanged;
private int m_pageSize = ;
/// <summary>
/// 每页显示数量
/// </summary>
[Description("每页显示数量"), Category("自定义")]
public virtual int PageSize
{
get { return m_pageSize; }
set { m_pageSize = value; }
}
private int startIndex = ;
/// <summary>
/// 开始的下标
/// </summary>
[Description("开始的下标"), Category("自定义")]
public virtual int StartIndex
{
get { return startIndex; }
set
{
startIndex = value;
if (startIndex <= )
startIndex = ;
}
} public UCPagerControlBase()
{
InitializeComponent();
} private void UCPagerControlBase_Load(object sender, EventArgs e)
{
if (DataSource == null)
ShowBtn(false, false);
else
{
ShowBtn(false, DataSource.Count > PageSize);
}
}
/// <summary>
/// 第一页
/// </summary>
public virtual void FirstPage()
{
if (DataSource == null)
return;
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 上一页
/// </summary>
public virtual void PreviousPage()
{
if (DataSource == null)
return;
if (startIndex == )
return;
startIndex -= m_pageSize;
if (startIndex < )
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 下一页
/// </summary>
public virtual void NextPage()
{
if (DataSource == null)
return;
if (startIndex + m_pageSize >= DataSource.Count)
{
return;
}
startIndex += m_pageSize;
if (startIndex < )
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 最后一页
/// </summary>
public virtual void EndPage()
{
if (DataSource == null)
return;
startIndex = DataSource.Count - m_pageSize;
if (startIndex < )
startIndex = ;
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 刷新数据
/// </summary>
public virtual void Reload()
{
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
/// <summary>
/// 获取当前页数据
/// </summary>
/// <returns></returns>
public virtual List<object> GetCurrentSource()
{
if (DataSource == null)
return null;
int intShowCount = m_pageSize;
if (intShowCount + startIndex > DataSource.Count)
intShowCount = DataSource.Count - startIndex;
object[] objs = new object[intShowCount];
DataSource.CopyTo(startIndex, objs, , intShowCount);
var lst = objs.ToList(); bool blnLeft = false;
bool blnRight = false;
if (lst.Count > )
{
if (DataSource.IndexOf(lst[]) > )
{
blnLeft = true;
}
else
{
blnLeft = false;
}
if (DataSource.IndexOf(lst[lst.Count - ]) >= DataSource.Count - )
{
blnRight = false;
}
else
{
blnRight = true;
}
}
ShowBtn(blnLeft, blnRight);
return lst;
} /// <summary>
/// 控制按钮显示
/// </summary>
/// <param name="blnLeftBtn">是否显示上一页,第一页</param>
/// <param name="blnRightBtn">是否显示下一页,最后一页</param>
protected virtual void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{ }
}
}
接下来就是具体的实现分页控件了,我们将实现2种不同样式的分页控件以适应不通的场景,
第一种
添加用户控件UCPagerControl,继承UCPagerControlBase
重新基类的部分函数
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
PreviousPage();
} private void panel2_MouseDown(object sender, MouseEventArgs e)
{
NextPage();
} private void panel3_MouseDown(object sender, MouseEventArgs e)
{
FirstPage();
} private void panel4_MouseDown(object sender, MouseEventArgs e)
{
EndPage();
} protected override void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{
panel1.Visible = panel3.Visible = blnLeftBtn;
panel2.Visible = panel4.Visible = blnRightBtn;
}
完成,是不是很简单,看下全部代码
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:UCPagerControl.cs
// 创建日期:2019-08-15 16:00:32
// 功能描述:PageControl
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace HZH_Controls.Controls
{
[ToolboxItem(true)]
public partial class UCPagerControl : UCPagerControlBase
{
public UCPagerControl()
{
InitializeComponent();
} private void panel1_MouseDown(object sender, MouseEventArgs e)
{
PreviousPage();
} private void panel2_MouseDown(object sender, MouseEventArgs e)
{
NextPage();
} private void panel3_MouseDown(object sender, MouseEventArgs e)
{
FirstPage();
} private void panel4_MouseDown(object sender, MouseEventArgs e)
{
EndPage();
} protected override void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{
panel1.Visible = panel3.Visible = blnLeftBtn;
panel2.Visible = panel4.Visible = blnRightBtn;
}
}
}
namespace HZH_Controls.Controls
{
partial class UCPagerControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.panel4 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1 = new System.Windows.Forms.Panel();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = ;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.Controls.Add(this.panel4, , );
this.tableLayoutPanel1.Controls.Add(this.panel3, , );
this.tableLayoutPanel1.Controls.Add(this.panel2, , );
this.tableLayoutPanel1.Controls.Add(this.panel1, , );
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(, );
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding();
this.tableLayoutPanel1.RowCount = ;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.TabIndex = ;
//
// panel4
//
this.panel4.BackgroundImage = global::HZH_Controls.Properties.Resources.end;
this.panel4.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.panel4.Location = new System.Drawing.Point(, );
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(, );
this.panel4.TabIndex = ;
this.panel4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel4_MouseDown);
//
// panel3
//
this.panel3.BackgroundImage = global::HZH_Controls.Properties.Resources.first;
this.panel3.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.panel3.Location = new System.Drawing.Point(, );
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(, );
this.panel3.TabIndex = ;
this.panel3.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel3_MouseDown);
//
// panel2
//
this.panel2.BackgroundImage = global::HZH_Controls.Properties.Resources.right;
this.panel2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.panel2.Location = new System.Drawing.Point(, );
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(, );
this.panel2.TabIndex = ;
this.panel2.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel2_MouseDown);
//
// panel1
//
this.panel1.BackgroundImage = global::HZH_Controls.Properties.Resources.left;
this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.panel1.Location = new System.Drawing.Point(, );
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(, );
this.panel1.TabIndex = ;
this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
//
// UCPagerControl
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "UCPagerControl";
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false); } #endregion private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel1;
}
}
第二种
这种和第一种的唯一区别就是页面计算生成的部分了
添加一个用户控件UCPagerControl2,继承UCPagerControlBase
属性如下
public override event PageControlEventHandler ShowSourceChanged; private List<object> m_dataSource;
public override List<object> DataSource
{
get
{
return m_dataSource;
}
set
{
m_dataSource = value;
if (m_dataSource == null)
m_dataSource = new List<object>();
ResetPageCount();
}
}
private int m_intPageSize = ;
public override int PageSize
{
get
{
return m_intPageSize;
}
set
{
m_intPageSize = value;
ResetPageCount();
}
}
其他更多的属性直接用基类的就可以
重写基类函数
public override void FirstPage()
{
if (PageIndex == )
return;
PageIndex = ;
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} public override void PreviousPage()
{
if (PageIndex <= )
{
return;
}
PageIndex--; StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} public override void NextPage()
{
if (PageIndex >= PageCount)
{
return;
}
PageIndex++;
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} public override void EndPage()
{
if (PageIndex == PageCount)
return;
PageIndex = PageCount;
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} protected override void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{
btnFirst.Enabled = btnPrevious.Enabled = blnLeftBtn;
btnNext.Enabled = btnEnd.Enabled = blnRightBtn;
}
一个重置总页数的函数
private void ResetPageCount()
{
if (PageSize > )
{
PageCount = m_dataSource.Count / m_intPageSize + (m_dataSource.Count % m_intPageSize > ? : );
}
txtPage.MaxValue = PageCount;
txtPage.MinValue = ;
ReloadPage();
}
一个重置计算当前页码列表的函数
private void ReloadPage()
{
try
{
ControlHelper.FreezeControl(tableLayoutPanel1, true);
List<int> lst = new List<int>(); if (PageCount <= )
{
for (var i = ; i <= PageCount; i++)
{
lst.Add(i);
}
}
else
{
if (this.PageIndex <= )
{
for (var i = ; i <= ; i++)
{
lst.Add(i);
}
lst.Add(-);
lst.Add(PageCount);
}
else if (this.PageIndex > PageCount - )
{
lst.Add();
lst.Add(-);
for (var i = PageCount - ; i <= PageCount; i++)
{
lst.Add(i);
}
}
else
{
lst.Add();
lst.Add(-);
var begin = PageIndex - ;
var end = PageIndex + ;
if (end > PageCount)
{
end = PageCount;
begin = end - ;
if (PageIndex - begin < )
{
begin = begin - ;
}
}
else if (end + == PageCount)
{
end = PageCount;
}
for (var i = begin; i <= end; i++)
{
lst.Add(i);
}
if (end != PageCount)
{
lst.Add(-);
lst.Add(PageCount);
}
}
} for (int i = ; i < ; i++)
{
UCBtnExt c = (UCBtnExt)this.tableLayoutPanel1.Controls.Find("p" + (i + ), false)[];
if (i >= lst.Count)
{
c.Visible = false;
}
else
{
if (lst[i] == -)
{
c.BtnText = "...";
c.Enabled = false;
}
else
{
c.BtnText = lst[i].ToString();
c.Enabled = true;
}
c.Visible = true;
if (lst[i] == PageIndex)
{
c.RectColor = Color.FromArgb(, , );
}
else
{
c.RectColor = Color.FromArgb(, , );
}
}
}
ShowBtn(PageIndex > , PageIndex < PageCount);
}
finally
{
ControlHelper.FreezeControl(tableLayoutPanel1, false);
}
}
跳转页面
private void page_BtnClick(object sender, EventArgs e)
{
PageIndex = (sender as UCBtnExt).BtnText.ToInt();
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
private void btnFirst_BtnClick(object sender, EventArgs e)
{
FirstPage();
} private void btnPrevious_BtnClick(object sender, EventArgs e)
{
PreviousPage();
} private void btnNext_BtnClick(object sender, EventArgs e)
{
NextPage();
} private void btnEnd_BtnClick(object sender, EventArgs e)
{
EndPage();
} private void btnToPage_BtnClick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtPage.InputText))
{
PageIndex = txtPage.InputText.ToInt();
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
}
至此完成所有逻辑,看下完整代码
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:UCPagerControl2.cs
// 创建日期:2019-08-15 16:00:37
// 功能描述:PageControl
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace HZH_Controls.Controls.List
{
[ToolboxItem(true)]
public partial class UCPagerControl2 : UCPagerControlBase
{
public UCPagerControl2()
{
InitializeComponent();
txtPage.txtInput.KeyDown += txtInput_KeyDown;
} void txtInput_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btnToPage_BtnClick(null, null);
txtPage.InputText = "";
}
} public override event PageControlEventHandler ShowSourceChanged; private List<object> m_dataSource;
public override List<object> DataSource
{
get
{
return m_dataSource;
}
set
{
m_dataSource = value;
if (m_dataSource == null)
m_dataSource = new List<object>();
ResetPageCount();
}
}
private int m_intPageSize = ;
public override int PageSize
{
get
{
return m_intPageSize;
}
set
{
m_intPageSize = value;
ResetPageCount();
}
} public override void FirstPage()
{
if (PageIndex == )
return;
PageIndex = ;
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} public override void PreviousPage()
{
if (PageIndex <= )
{
return;
}
PageIndex--; StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} public override void NextPage()
{
if (PageIndex >= PageCount)
{
return;
}
PageIndex++;
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} public override void EndPage()
{
if (PageIndex == PageCount)
return;
PageIndex = PageCount;
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} private void ResetPageCount()
{
if (PageSize > )
{
PageCount = m_dataSource.Count / m_intPageSize + (m_dataSource.Count % m_intPageSize > ? : );
}
txtPage.MaxValue = PageCount;
txtPage.MinValue = ;
ReloadPage();
} private void ReloadPage()
{
try
{
ControlHelper.FreezeControl(tableLayoutPanel1, true);
List<int> lst = new List<int>(); if (PageCount <= )
{
for (var i = ; i <= PageCount; i++)
{
lst.Add(i);
}
}
else
{
if (this.PageIndex <= )
{
for (var i = ; i <= ; i++)
{
lst.Add(i);
}
lst.Add(-);
lst.Add(PageCount);
}
else if (this.PageIndex > PageCount - )
{
lst.Add();
lst.Add(-);
for (var i = PageCount - ; i <= PageCount; i++)
{
lst.Add(i);
}
}
else
{
lst.Add();
lst.Add(-);
var begin = PageIndex - ;
var end = PageIndex + ;
if (end > PageCount)
{
end = PageCount;
begin = end - ;
if (PageIndex - begin < )
{
begin = begin - ;
}
}
else if (end + == PageCount)
{
end = PageCount;
}
for (var i = begin; i <= end; i++)
{
lst.Add(i);
}
if (end != PageCount)
{
lst.Add(-);
lst.Add(PageCount);
}
}
} for (int i = ; i < ; i++)
{
UCBtnExt c = (UCBtnExt)this.tableLayoutPanel1.Controls.Find("p" + (i + ), false)[];
if (i >= lst.Count)
{
c.Visible = false;
}
else
{
if (lst[i] == -)
{
c.BtnText = "...";
c.Enabled = false;
}
else
{
c.BtnText = lst[i].ToString();
c.Enabled = true;
}
c.Visible = true;
if (lst[i] == PageIndex)
{
c.RectColor = Color.FromArgb(, , );
}
else
{
c.RectColor = Color.FromArgb(, , );
}
}
}
ShowBtn(PageIndex > , PageIndex < PageCount);
}
finally
{
ControlHelper.FreezeControl(tableLayoutPanel1, false);
}
} private void page_BtnClick(object sender, EventArgs e)
{
PageIndex = (sender as UCBtnExt).BtnText.ToInt();
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource(); if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
} protected override void ShowBtn(bool blnLeftBtn, bool blnRightBtn)
{
btnFirst.Enabled = btnPrevious.Enabled = blnLeftBtn;
btnNext.Enabled = btnEnd.Enabled = blnRightBtn;
} private void btnFirst_BtnClick(object sender, EventArgs e)
{
FirstPage();
} private void btnPrevious_BtnClick(object sender, EventArgs e)
{
PreviousPage();
} private void btnNext_BtnClick(object sender, EventArgs e)
{
NextPage();
} private void btnEnd_BtnClick(object sender, EventArgs e)
{
EndPage();
} private void btnToPage_BtnClick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtPage.InputText))
{
PageIndex = txtPage.InputText.ToInt();
StartIndex = (PageIndex - ) * PageSize;
ReloadPage();
var s = GetCurrentSource();
if (ShowSourceChanged != null)
{
ShowSourceChanged(s);
}
}
} }
}
namespace HZH_Controls.Controls.List
{
partial class UCPagerControl2
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnFirst = new HZH_Controls.Controls.UCBtnExt();
this.btnPrevious = new HZH_Controls.Controls.UCBtnExt();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.p9 = new HZH_Controls.Controls.UCBtnExt();
this.p1 = new HZH_Controls.Controls.UCBtnExt();
this.btnToPage = new HZH_Controls.Controls.UCBtnExt();
this.btnEnd = new HZH_Controls.Controls.UCBtnExt();
this.btnNext = new HZH_Controls.Controls.UCBtnExt();
this.p8 = new HZH_Controls.Controls.UCBtnExt();
this.p7 = new HZH_Controls.Controls.UCBtnExt();
this.p6 = new HZH_Controls.Controls.UCBtnExt();
this.p5 = new HZH_Controls.Controls.UCBtnExt();
this.p4 = new HZH_Controls.Controls.UCBtnExt();
this.p3 = new HZH_Controls.Controls.UCBtnExt();
this.p2 = new HZH_Controls.Controls.UCBtnExt();
this.txtPage = new HZH_Controls.Controls.UCTextBoxEx();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
// btnFirst
//
this.btnFirst.BackColor = System.Drawing.Color.White;
this.btnFirst.BtnBackColor = System.Drawing.Color.White;
this.btnFirst.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.btnFirst.BtnForeColor = System.Drawing.Color.Gray;
this.btnFirst.BtnText = "<<";
this.btnFirst.ConerRadius = ;
this.btnFirst.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnFirst.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnFirst.FillColor = System.Drawing.Color.White;
this.btnFirst.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnFirst.IsRadius = true;
this.btnFirst.IsShowRect = true;
this.btnFirst.IsShowTips = false;
this.btnFirst.Location = new System.Drawing.Point(, );
this.btnFirst.Margin = new System.Windows.Forms.Padding();
this.btnFirst.Name = "btnFirst";
this.btnFirst.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnFirst.RectWidth = ;
this.btnFirst.Size = new System.Drawing.Size(, );
this.btnFirst.TabIndex = ;
this.btnFirst.TabStop = false;
this.btnFirst.TipsText = "";
this.btnFirst.BtnClick += new System.EventHandler(this.btnFirst_BtnClick);
//
// btnPrevious
//
this.btnPrevious.BackColor = System.Drawing.Color.White;
this.btnPrevious.BtnBackColor = System.Drawing.Color.White;
this.btnPrevious.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.btnPrevious.BtnForeColor = System.Drawing.Color.Gray;
this.btnPrevious.BtnText = "<";
this.btnPrevious.ConerRadius = ;
this.btnPrevious.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnPrevious.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnPrevious.FillColor = System.Drawing.Color.White;
this.btnPrevious.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnPrevious.IsRadius = true;
this.btnPrevious.IsShowRect = true;
this.btnPrevious.IsShowTips = false;
this.btnPrevious.Location = new System.Drawing.Point(, );
this.btnPrevious.Margin = new System.Windows.Forms.Padding();
this.btnPrevious.Name = "btnPrevious";
this.btnPrevious.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnPrevious.RectWidth = ;
this.btnPrevious.Size = new System.Drawing.Size(, );
this.btnPrevious.TabIndex = ;
this.btnPrevious.TabStop = false;
this.btnPrevious.TipsText = "";
this.btnPrevious.BtnClick += new System.EventHandler(this.btnPrevious_BtnClick);
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.tableLayoutPanel1.ColumnCount = ;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 70F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 70F));
this.tableLayoutPanel1.Controls.Add(this.p9, , );
this.tableLayoutPanel1.Controls.Add(this.p1, , );
this.tableLayoutPanel1.Controls.Add(this.btnToPage, , );
this.tableLayoutPanel1.Controls.Add(this.btnEnd, , );
this.tableLayoutPanel1.Controls.Add(this.btnNext, , );
this.tableLayoutPanel1.Controls.Add(this.p8, , );
this.tableLayoutPanel1.Controls.Add(this.p7, , );
this.tableLayoutPanel1.Controls.Add(this.p6, , );
this.tableLayoutPanel1.Controls.Add(this.p5, , );
this.tableLayoutPanel1.Controls.Add(this.p4, , );
this.tableLayoutPanel1.Controls.Add(this.p3, , );
this.tableLayoutPanel1.Controls.Add(this.p2, , );
this.tableLayoutPanel1.Controls.Add(this.btnPrevious, , );
this.tableLayoutPanel1.Controls.Add(this.btnFirst, , );
this.tableLayoutPanel1.Controls.Add(this.txtPage, , );
this.tableLayoutPanel1.Location = new System.Drawing.Point(, );
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = ;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.TabIndex = ;
//
// p9
//
this.p9.BackColor = System.Drawing.Color.White;
this.p9.BtnBackColor = System.Drawing.Color.White;
this.p9.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p9.BtnForeColor = System.Drawing.Color.Gray;
this.p9.BtnText = "";
this.p9.ConerRadius = ;
this.p9.Cursor = System.Windows.Forms.Cursors.Hand;
this.p9.Dock = System.Windows.Forms.DockStyle.Fill;
this.p9.FillColor = System.Drawing.Color.White;
this.p9.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p9.IsRadius = true;
this.p9.IsShowRect = true;
this.p9.IsShowTips = false;
this.p9.Location = new System.Drawing.Point(, );
this.p9.Margin = new System.Windows.Forms.Padding(, , , );
this.p9.Name = "p9";
this.p9.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p9.RectWidth = ;
this.p9.Size = new System.Drawing.Size(, );
this.p9.TabIndex = ;
this.p9.TabStop = false;
this.p9.TipsText = "";
this.p9.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p1
//
this.p1.BackColor = System.Drawing.Color.White;
this.p1.BtnBackColor = System.Drawing.Color.White;
this.p1.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p1.BtnForeColor = System.Drawing.Color.Gray;
this.p1.BtnText = "";
this.p1.ConerRadius = ;
this.p1.Cursor = System.Windows.Forms.Cursors.Hand;
this.p1.Dock = System.Windows.Forms.DockStyle.Fill;
this.p1.FillColor = System.Drawing.Color.White;
this.p1.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p1.IsRadius = true;
this.p1.IsShowRect = true;
this.p1.IsShowTips = false;
this.p1.Location = new System.Drawing.Point(, );
this.p1.Margin = new System.Windows.Forms.Padding(, , , );
this.p1.Name = "p1";
this.p1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p1.RectWidth = ;
this.p1.Size = new System.Drawing.Size(, );
this.p1.TabIndex = ;
this.p1.TabStop = false;
this.p1.TipsText = "";
this.p1.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// btnToPage
//
this.btnToPage.BackColor = System.Drawing.Color.White;
this.btnToPage.BtnBackColor = System.Drawing.Color.White;
this.btnToPage.BtnFont = new System.Drawing.Font("微软雅黑", 11F);
this.btnToPage.BtnForeColor = System.Drawing.Color.Gray;
this.btnToPage.BtnText = "跳转";
this.btnToPage.ConerRadius = ;
this.btnToPage.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnToPage.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnToPage.FillColor = System.Drawing.Color.White;
this.btnToPage.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnToPage.IsRadius = true;
this.btnToPage.IsShowRect = true;
this.btnToPage.IsShowTips = false;
this.btnToPage.Location = new System.Drawing.Point(, );
this.btnToPage.Margin = new System.Windows.Forms.Padding();
this.btnToPage.Name = "btnToPage";
this.btnToPage.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnToPage.RectWidth = ;
this.btnToPage.Size = new System.Drawing.Size(, );
this.btnToPage.TabIndex = ;
this.btnToPage.TabStop = false;
this.btnToPage.TipsText = "";
this.btnToPage.BtnClick += new System.EventHandler(this.btnToPage_BtnClick);
//
// btnEnd
//
this.btnEnd.BackColor = System.Drawing.Color.White;
this.btnEnd.BtnBackColor = System.Drawing.Color.White;
this.btnEnd.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.btnEnd.BtnForeColor = System.Drawing.Color.Gray;
this.btnEnd.BtnText = ">>";
this.btnEnd.ConerRadius = ;
this.btnEnd.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnEnd.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnEnd.FillColor = System.Drawing.Color.White;
this.btnEnd.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnEnd.IsRadius = true;
this.btnEnd.IsShowRect = true;
this.btnEnd.IsShowTips = false;
this.btnEnd.Location = new System.Drawing.Point(, );
this.btnEnd.Margin = new System.Windows.Forms.Padding();
this.btnEnd.Name = "btnEnd";
this.btnEnd.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnEnd.RectWidth = ;
this.btnEnd.Size = new System.Drawing.Size(, );
this.btnEnd.TabIndex = ;
this.btnEnd.TabStop = false;
this.btnEnd.TipsText = "";
this.btnEnd.BtnClick += new System.EventHandler(this.btnEnd_BtnClick);
//
// btnNext
//
this.btnNext.BackColor = System.Drawing.Color.White;
this.btnNext.BtnBackColor = System.Drawing.Color.White;
this.btnNext.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.btnNext.BtnForeColor = System.Drawing.Color.Gray;
this.btnNext.BtnText = ">";
this.btnNext.ConerRadius = ;
this.btnNext.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnNext.Dock = System.Windows.Forms.DockStyle.Fill;
this.btnNext.FillColor = System.Drawing.Color.White;
this.btnNext.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.btnNext.IsRadius = true;
this.btnNext.IsShowRect = true;
this.btnNext.IsShowTips = false;
this.btnNext.Location = new System.Drawing.Point(, );
this.btnNext.Margin = new System.Windows.Forms.Padding();
this.btnNext.Name = "btnNext";
this.btnNext.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.btnNext.RectWidth = ;
this.btnNext.Size = new System.Drawing.Size(, );
this.btnNext.TabIndex = ;
this.btnNext.TabStop = false;
this.btnNext.TipsText = "";
this.btnNext.BtnClick += new System.EventHandler(this.btnNext_BtnClick);
//
// p8
//
this.p8.BackColor = System.Drawing.Color.White;
this.p8.BtnBackColor = System.Drawing.Color.White;
this.p8.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p8.BtnForeColor = System.Drawing.Color.Gray;
this.p8.BtnText = "";
this.p8.ConerRadius = ;
this.p8.Cursor = System.Windows.Forms.Cursors.Hand;
this.p8.Dock = System.Windows.Forms.DockStyle.Fill;
this.p8.FillColor = System.Drawing.Color.White;
this.p8.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p8.IsRadius = true;
this.p8.IsShowRect = true;
this.p8.IsShowTips = false;
this.p8.Location = new System.Drawing.Point(, );
this.p8.Margin = new System.Windows.Forms.Padding(, , , );
this.p8.Name = "p8";
this.p8.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p8.RectWidth = ;
this.p8.Size = new System.Drawing.Size(, );
this.p8.TabIndex = ;
this.p8.TabStop = false;
this.p8.TipsText = "";
this.p8.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p7
//
this.p7.BackColor = System.Drawing.Color.White;
this.p7.BtnBackColor = System.Drawing.Color.White;
this.p7.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p7.BtnForeColor = System.Drawing.Color.Gray;
this.p7.BtnText = "";
this.p7.ConerRadius = ;
this.p7.Cursor = System.Windows.Forms.Cursors.Hand;
this.p7.Dock = System.Windows.Forms.DockStyle.Fill;
this.p7.FillColor = System.Drawing.Color.White;
this.p7.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p7.IsRadius = true;
this.p7.IsShowRect = true;
this.p7.IsShowTips = false;
this.p7.Location = new System.Drawing.Point(, );
this.p7.Margin = new System.Windows.Forms.Padding(, , , );
this.p7.Name = "p7";
this.p7.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p7.RectWidth = ;
this.p7.Size = new System.Drawing.Size(, );
this.p7.TabIndex = ;
this.p7.TabStop = false;
this.p7.TipsText = "";
this.p7.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p6
//
this.p6.BackColor = System.Drawing.Color.White;
this.p6.BtnBackColor = System.Drawing.Color.White;
this.p6.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p6.BtnForeColor = System.Drawing.Color.Gray;
this.p6.BtnText = "";
this.p6.ConerRadius = ;
this.p6.Cursor = System.Windows.Forms.Cursors.Hand;
this.p6.Dock = System.Windows.Forms.DockStyle.Fill;
this.p6.FillColor = System.Drawing.Color.White;
this.p6.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p6.IsRadius = true;
this.p6.IsShowRect = true;
this.p6.IsShowTips = false;
this.p6.Location = new System.Drawing.Point(, );
this.p6.Margin = new System.Windows.Forms.Padding(, , , );
this.p6.Name = "p6";
this.p6.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p6.RectWidth = ;
this.p6.Size = new System.Drawing.Size(, );
this.p6.TabIndex = ;
this.p6.TabStop = false;
this.p6.TipsText = "";
this.p6.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p5
//
this.p5.BackColor = System.Drawing.Color.White;
this.p5.BtnBackColor = System.Drawing.Color.White;
this.p5.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p5.BtnForeColor = System.Drawing.Color.Gray;
this.p5.BtnText = "";
this.p5.ConerRadius = ;
this.p5.Cursor = System.Windows.Forms.Cursors.Hand;
this.p5.Dock = System.Windows.Forms.DockStyle.Fill;
this.p5.FillColor = System.Drawing.Color.White;
this.p5.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p5.IsRadius = true;
this.p5.IsShowRect = true;
this.p5.IsShowTips = false;
this.p5.Location = new System.Drawing.Point(, );
this.p5.Margin = new System.Windows.Forms.Padding(, , , );
this.p5.Name = "p5";
this.p5.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p5.RectWidth = ;
this.p5.Size = new System.Drawing.Size(, );
this.p5.TabIndex = ;
this.p5.TabStop = false;
this.p5.TipsText = "";
this.p5.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p4
//
this.p4.BackColor = System.Drawing.Color.White;
this.p4.BtnBackColor = System.Drawing.Color.White;
this.p4.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p4.BtnForeColor = System.Drawing.Color.Gray;
this.p4.BtnText = "";
this.p4.ConerRadius = ;
this.p4.Cursor = System.Windows.Forms.Cursors.Hand;
this.p4.Dock = System.Windows.Forms.DockStyle.Fill;
this.p4.FillColor = System.Drawing.Color.White;
this.p4.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p4.IsRadius = true;
this.p4.IsShowRect = true;
this.p4.IsShowTips = false;
this.p4.Location = new System.Drawing.Point(, );
this.p4.Margin = new System.Windows.Forms.Padding(, , , );
this.p4.Name = "p4";
this.p4.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p4.RectWidth = ;
this.p4.Size = new System.Drawing.Size(, );
this.p4.TabIndex = ;
this.p4.TabStop = false;
this.p4.TipsText = "";
this.p4.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p3
//
this.p3.BackColor = System.Drawing.Color.White;
this.p3.BtnBackColor = System.Drawing.Color.White;
this.p3.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p3.BtnForeColor = System.Drawing.Color.Gray;
this.p3.BtnText = "";
this.p3.ConerRadius = ;
this.p3.Cursor = System.Windows.Forms.Cursors.Hand;
this.p3.Dock = System.Windows.Forms.DockStyle.Fill;
this.p3.FillColor = System.Drawing.Color.White;
this.p3.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p3.IsRadius = true;
this.p3.IsShowRect = true;
this.p3.IsShowTips = false;
this.p3.Location = new System.Drawing.Point(, );
this.p3.Margin = new System.Windows.Forms.Padding(, , , );
this.p3.Name = "p3";
this.p3.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p3.RectWidth = ;
this.p3.Size = new System.Drawing.Size(, );
this.p3.TabIndex = ;
this.p3.TabStop = false;
this.p3.TipsText = "";
this.p3.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// p2
//
this.p2.BackColor = System.Drawing.Color.White;
this.p2.BtnBackColor = System.Drawing.Color.White;
this.p2.BtnFont = new System.Drawing.Font("微软雅黑", 9F);
this.p2.BtnForeColor = System.Drawing.Color.Gray;
this.p2.BtnText = "";
this.p2.ConerRadius = ;
this.p2.Cursor = System.Windows.Forms.Cursors.Hand;
this.p2.Dock = System.Windows.Forms.DockStyle.Fill;
this.p2.FillColor = System.Drawing.Color.White;
this.p2.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.p2.IsRadius = true;
this.p2.IsShowRect = true;
this.p2.IsShowTips = false;
this.p2.Location = new System.Drawing.Point(, );
this.p2.Margin = new System.Windows.Forms.Padding(, , , );
this.p2.Name = "p2";
this.p2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.p2.RectWidth = ;
this.p2.Size = new System.Drawing.Size(, );
this.p2.TabIndex = ;
this.p2.TabStop = false;
this.p2.TipsText = "";
this.p2.BtnClick += new System.EventHandler(this.page_BtnClick);
//
// txtPage
//
this.txtPage.BackColor = System.Drawing.Color.Transparent;
this.txtPage.ConerRadius = ;
this.txtPage.Cursor = System.Windows.Forms.Cursors.IBeam;
this.txtPage.DecLength = ;
this.txtPage.FillColor = System.Drawing.Color.Empty;
this.txtPage.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.txtPage.ForeColor = System.Drawing.Color.Gray;
this.txtPage.InputText = "";
this.txtPage.InputType = HZH_Controls.TextInputType.PositiveInteger;
this.txtPage.IsFocusColor = true;
this.txtPage.IsRadius = true;
this.txtPage.IsShowClearBtn = false;
this.txtPage.IsShowKeyboard = false;
this.txtPage.IsShowRect = true;
this.txtPage.IsShowSearchBtn = false;
this.txtPage.KeyBoardType = HZH_Controls.Controls.KeyBoardType.UCKeyBorderAll_EN;
this.txtPage.Location = new System.Drawing.Point(, );
this.txtPage.Margin = new System.Windows.Forms.Padding(, , , );
this.txtPage.MaxValue = new decimal(new int[] {
,
,
,
});
this.txtPage.MinValue = new decimal(new int[] {
,
,
,
-});
this.txtPage.Name = "txtPage";
this.txtPage.Padding = new System.Windows.Forms.Padding();
this.txtPage.PromptColor = System.Drawing.Color.Silver;
this.txtPage.PromptFont = new System.Drawing.Font("微软雅黑", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
this.txtPage.PromptText = "页码";
this.txtPage.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.txtPage.RectWidth = ;
this.txtPage.RegexPattern = "";
this.txtPage.Size = new System.Drawing.Size(, );
this.txtPage.TabIndex = ;
//
// UCPagerControl2
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "UCPagerControl2";
this.Size = new System.Drawing.Size(, );
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false); } #endregion private UCBtnExt btnFirst;
private UCBtnExt btnPrevious;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private UCBtnExt btnEnd;
private UCBtnExt btnNext;
private UCBtnExt p8;
private UCBtnExt p7;
private UCBtnExt p6;
private UCBtnExt p5;
private UCBtnExt p4;
private UCBtnExt p3;
private UCBtnExt p2;
private UCBtnExt btnToPage;
private UCTextBoxEx txtPage;
private UCBtnExt p9;
private UCBtnExt p1;
}
}
用处及效果
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星 星吧
(十二)c#Winform自定义控件-分页控件的更多相关文章
- Spring Boot 项目学习 (二) MySql + MyBatis 注解 + 分页控件 配置
0 引言 本文主要在Spring Boot 基础项目的基础上,添加 Mysql .MyBatis(注解方式)与 分页控件 的配置,用于协助完成数据库操作. 1 创建数据表 这个过程就暂时省略了. 2 ...
- Winform自定义分页控件的实现
实现效果 有点丑陋 但是功能是没问题的 测试过 实现思路 先创建一个用户控件 代码实现 public partial class PagerControl : UserControl { ; /// ...
- winform 自定义分页控件 及DataGridview数据绑定
分页效果如上图所示,用到的控件均为基本控件 ,其方法如下 右击项目-添加-新建项 选择用户控件 然后在用户控件中拖入所需要的Label,Button,Text 用户控件全部代码: using Syst ...
- winform自定义分页控件
1.控件代码: public partial class PagerControl : UserControl { #region 构造函数 public PagerControl() { Initi ...
- (三十六)c#Winform自定义控件-步骤控件-HZHControls
官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...
- (三十三)c#Winform自定义控件-日期控件
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- iOs基础篇(二十二)—— UIPickerView、UIDatePicker控件的使用
一.UIPickerView UIPickerView是一个选择器控件,可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. 1.常用属性 (1)num ...
- [转]Oracle分页之二:自定义web分页控件的封装
本文转自:http://www.cnblogs.com/scy251147/archive/2011/04/16/2018326.html 上节中,讲述的就是Oracle存储过程分页的使用方式,但是如 ...
- LabVIEW(十二):VI本地化-控件标题内容的修改
一.对于一般LabVIEW的学习,很少遇到本地化的问题但是我们经常会遇到界面控件标题的显示问题.由于各个技术领域的专业性,往往用户对VI界面的显示有自己的要求,其中就包括控件的标题问题,这可以理解成本 ...
随机推荐
- Bzoj 4582 [Usaco2016 Open] Diamond Collector 题解
4582: [Usaco2016 Open]Diamond Collector Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 204 Solved: ...
- kali linux 常用文件与指令路径
重启网络 : /etc/init.d/networking restart 语言设置文件 : /etc/default/locale apt 安装deb保存目录 : /var/cache/apt/ar ...
- 6.1.初识Flutter应用之实现一个计数器
用Android Studio和VS Code创建的Flutter应用模板是一个简单的计数器示例,本节先仔细讲解一下这个计数器Demo的源码,让读者对Flutter应用程序结构有个基本了解,在随后小节 ...
- C#3.0新增功能07 查询表达式
连载目录 [已更新最新开发文章,点击查看详细] 查询是什么及其作用是什么 查询是一组指令,描述要从给定数据源(或源)检索的数据以及返回的数据应具有的形状和组织. 查询与它生成的结果不同. 通常情 ...
- 【git】15分钟学会使用Git和远程代码库
Git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...
- Java Web项目案例之---登录和注册(精华版)
登录和注册(精华版) (一)实现功能 1.使用cookie记录登录成功的用户名,用户选择记住用户名,则用户再次登录时用户名自动显示 2.实现文件上传功能(上传文件的表单上传于普通的表单上传不同,必须是 ...
- C语言数据类型及变量整理
数据类型 获取int的字节数大小方法 printf("int bytes:%d",sizeof(int)); 列表整理 类型 字节数 取值范围 char 1 [-128,127]= ...
- Java oop 多态
1.多态指对象的多种形态:引用多态与方法多态 注意: A:继承是多态的实现基础 B:方法重写也是多态的体现 2.引用多态 A:父类的引用可以指向本类的对象:父类 对象名 = new 父类( ...
- 【Mac】Mac 使用 zsh 后, mvn 命令无效
如题-- 解决方法: 将 maven 的环境变量配置放到 .zshrc 文件中. 参考链接: http://ruby-china.org/topics/23158 https://yq.aliyun. ...
- 【iOS】duplicate symbols for architecture x86_64
今天遇到了这个问题,错误如下: duplicate symbol _OBJC_IVAR_$_BCViewController.bank in: /Users/***/Library/Developer ...