WinForm 分页控件

测试截图

控件设计

新建一个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.DockStyle.Fi
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值