测试截图
控件设计
新建一个Pagination类,继承自System.Windows.Forms.UserControl。设定好用户控件的大小,托入一个TableLayoutPanel控件到UserControl上,根据实际情况布局好所需控件,如上图所示。(注:以下源码中的Button和TextBox继承自自定义的控件,非WinForm原生控件,因此部分属性原生控件可能不存在,请自行根据情况修改)
控件源码
namespace WinFormFramework.Controls
{
[System.ComponentModel.DefaultEvent("PageChanged")]
public class Pagination : System.Windows.Forms.UserControl
{
#region 构造
public Pagination()
{
InitializeComponent();
InitializeConfig();
}
#endregion
#region 属性
private Button ButtonFirstPage;
private Button ButtonPreviousPage;
private Button ButtonPage1;
private Button ButtonPage2;
private Button ButtonPage3;
private Button ButtonPage4;
private Button ButtonPage5;
private Button ButtonNextPage;
private Button ButtonLastPage;
private Button ButtonGoToPage;
private TextBox TextBoxPageNumber;
private System.Windows.Forms.TableLayoutPanel TableLayoutPanelMain;
private void InitializeComponent()
{
TableLayoutPanelMain = new System.Windows.Forms.TableLayoutPanel();
ButtonFirstPage = new WinFormFramework.Controls.Button();
ButtonPreviousPage = new WinFormFramework.Controls.Button();
ButtonPage1 = new WinFormFramework.Controls.Button();
ButtonPage2 = new WinFormFramework.Controls.Button();
ButtonPage3 = new WinFormFramework.Controls.Button();
ButtonPage4 = new WinFormFramework.Controls.Button();
ButtonPage5 = new WinFormFramework.Controls.Button();
ButtonNextPage = new WinFormFramework.Controls.Button();
ButtonLastPage = new WinFormFramework.Controls.Button();
ButtonGoToPage = new WinFormFramework.Controls.Button();
TextBoxPageNumber = new WinFormFramework.Controls.TextBox();
TableLayoutPanelMain.SuspendLayout();
SuspendLayout();
//
// TableLayoutPanelMain
//
TableLayoutPanelMain.ColumnCount = 11;
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
TableLayoutPanelMain.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 9F));
TableLayoutPanelMain.Controls.Add(ButtonFirstPage, 0, 0);
TableLayoutPanelMain.Controls.Add(ButtonPreviousPage, 1, 0);
TableLayoutPanelMain.Controls.Add(ButtonPage1, 2, 0);
TableLayoutPanelMain.Controls.Add(ButtonPage2, 3, 0);
TableLayoutPanelMain.Controls.Add(ButtonPage3, 4, 0);
TableLayoutPanelMain.Controls.Add(ButtonPage4, 5, 0);
TableLayoutPanelMain.Controls.Add(ButtonPage5, 6, 0);
TableLayoutPanelMain.Controls.Add(ButtonNextPage, 7, 0);
TableLayoutPanelMain.Controls.Add(ButtonLastPage, 8, 0);
TableLayoutPanelMain.Controls.Add(ButtonGoToPage, 10, 0);
TableLayoutPanelMain.Controls.Add(TextBoxPageNumber, 9, 0);
TableLayoutPanelMain.Dock = System.Windows.Forms.DockStyle.Fill;
TableLayoutPanelMain.Location = new System.Drawing.Point(0, 0);
TableLayoutPanelMain.Name = "TableLayoutPanelMain";
TableLayoutPanelMain.RowCount = 1;
TableLayoutPanelMain.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
TableLayoutPanelMain.Size = new System.Drawing.Size(330, 24);
TableLayoutPanelMain.TabIndex = 0;
//
// ButtonFirstPage
//
ButtonFirstPage.BorderColor = System.Drawing.Color.LightGray;
ButtonFirstPage.Dock = System.Windows.Forms