(十二)c#Winform自定义控件-分页控件

准备工作

当一个列表加载数据过多时,比如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 = 1;
        /// <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 = 1;
        /// <summary>
        /// 每页显示数量
        /// </summary>
        [Description("每页显示数量"), Category("自定义")]
        public virtual int PageSize
        {
            get { return m_pageSize; }
            set { m_pageSize = value; }
        }
        private int startIndex = 0;
        /// <summary>
        /// 开始的下标
        /// </summary>
        [Description("开始的下标"), Category("自定义")]
        public virtual int StartIndex
        {
            get { return startIndex; }
            set
            {
                startIndex = value;
                if (startIndex <= 0)
                    startIndex = 0;
            }
        }

然后定义虚函数,并做一些默认实现

/// <summary>
        /// 第一页
        /// </summary>
        public virtual void FirstPage()
        {
            if (DataSource == null)
                return;
            startIndex = 0;
            var s = GetCurrentSource();

            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }
        /// <summary>
        /// 上一页
        /// </summary>
        public virtual void PreviousPage()
        {
            if (DataSource == null)
                return;
            if (startIndex == 0)
                return;
            startIndex -= m_pageSize;
            if (startIndex < 0)
                startIndex = 0;
            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 < 0)
                startIndex = 0;
            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 < 0)
                startIndex = 0;
            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, 0, intShowCount);
            var lst = objs.ToList();

            bool blnLeft = false;
            bool blnRight = false;
            if (lst.Count > 0)
            {
                if (DataSource.IndexOf(lst[0]) > 0)
                {
                    blnLeft = true;
                }
                else
                {
                    blnLeft = false;
                }
                if (DataSource.IndexOf(lst[lst.Count - 1]) >= DataSource.Count - 1)
                {
                    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(304, 58);
            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 = 1;
        /// <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 = 1;
        /// <summary>
        /// 每页显示数量
        /// </summary>
        [Description("每页显示数量"), Category("自定义")]
        public virtual int PageSize
        {
            get { return m_pageSize; }
            set { m_pageSize = value; }
        }
        private int startIndex = 0;
        /// <summary>
        /// 开始的下标
        /// </summary>
        [Description("开始的下标"), Category("自定义")]
        public virtual int StartIndex
        {
            get { return startIndex; }
            set
            {
                startIndex = value;
                if (startIndex <= 0)
                    startIndex = 0;
            }
        }

        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 = 0;
            var s = GetCurrentSource();

            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }
        /// <summary>
        /// 上一页
        /// </summary>
        public virtual void PreviousPage()
        {
            if (DataSource == null)
                return;
            if (startIndex == 0)
                return;
            startIndex -= m_pageSize;
            if (startIndex < 0)
                startIndex = 0;
            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 < 0)
                startIndex = 0;
            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 < 0)
                startIndex = 0;
            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, 0, intShowCount);
            var lst = objs.ToList();

            bool blnLeft = false;
            bool blnRight = false;
            if (lst.Count > 0)
            {
                if (DataSource.IndexOf(lst[0]) > 0)
                {
                    blnLeft = true;
                }
                else
                {
                    blnLeft = false;
                }
                if (DataSource.IndexOf(lst[lst.Count - 1]) >= DataSource.Count - 1)
                {
                    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 = 4;
            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, 3, 0);
            this.tableLayoutPanel1.Controls.Add(this.panel3, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.panel2, 2, 0);
            this.tableLayoutPanel1.Controls.Add(this.panel1, 1, 0);
            this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.Padding = new System.Windows.Forms.Padding(3);
            this.tableLayoutPanel1.RowCount = 1;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(304, 58);
            this.tableLayoutPanel1.TabIndex = 1;
            // 
            // 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(228, 6);
            this.panel4.Name = "panel4";
            this.panel4.Size = new System.Drawing.Size(68, 46);
            this.panel4.TabIndex = 3;
            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(6, 6);
            this.panel3.Name = "panel3";
            this.panel3.Size = new System.Drawing.Size(68, 46);
            this.panel3.TabIndex = 2;
            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(154, 6);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(68, 46);
            this.panel2.TabIndex = 1;
            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(80, 6);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(68, 46);
            this.panel1.TabIndex = 0;
            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 = 0;
        public override int PageSize
        {
            get
            {
                return m_intPageSize;
            }
            set
            {
                m_intPageSize = value;
                ResetPageCount();
            }
        }

其他更多的属性直接用基类的就可以

重写基类函数

public override void FirstPage()
        {
            if (PageIndex == 1)
                return;
            PageIndex = 1;
            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        public override void PreviousPage()
        {
            if (PageIndex <= 1)
            {
                return;
            }
            PageIndex--;

            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        public override void NextPage()
        {
            if (PageIndex >= PageCount)
            {
                return;
            }
            PageIndex++;
            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        public override void EndPage()
        {
            if (PageIndex == PageCount)
                return;
            PageIndex = PageCount;
            StartIndex = (PageIndex - 1) * 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 > 0)
            {
                PageCount = m_dataSource.Count / m_intPageSize + (m_dataSource.Count % m_intPageSize > 0 ? 1 : 0);
            }
            txtPage.MaxValue = PageCount;
            txtPage.MinValue = 1;
            ReloadPage();
        }

一个重置计算当前页码列表的函数

private void ReloadPage()
        {
            try
            {
                ControlHelper.FreezeControl(tableLayoutPanel1, true);
                List<int> lst = new List<int>();

                if (PageCount <= 9)
                {
                    for (var i = 1; i <= PageCount; i++)
                    {
                        lst.Add(i);
                    }
                }
                else
                {
                    if (this.PageIndex <= 6)
                    {
                        for (var i = 1; i <= 7; i++)
                        {
                            lst.Add(i);
                        }
                        lst.Add(-1);
                        lst.Add(PageCount);
                    }
                    else if (this.PageIndex > PageCount - 6)
                    {
                        lst.Add(1);
                        lst.Add(-1);
                        for (var i = PageCount - 6; i <= PageCount; i++)
                        {
                            lst.Add(i);
                        }
                    }
                    else
                    {
                        lst.Add(1);
                        lst.Add(-1);
                        var begin = PageIndex - 2;
                        var end = PageIndex + 2;
                        if (end > PageCount)
                        {
                            end = PageCount;
                            begin = end - 4;
                            if (PageIndex - begin < 2)
                            {
                                begin = begin - 1;
                            }
                        }
                        else if (end + 1 == PageCount)
                        {
                            end = PageCount;
                        }
                        for (var i = begin; i <= end; i++)
                        {
                            lst.Add(i);
                        }
                        if (end != PageCount)
                        {
                            lst.Add(-1);
                            lst.Add(PageCount);
                        }
                    }
                }

                for (int i = 0; i < 9; i++)
                {
                    UCBtnExt c = (UCBtnExt)this.tableLayoutPanel1.Controls.Find("p" + (i + 1), false)[0];
                    if (i >= lst.Count)
                    {
                        c.Visible = false;
                    }
                    else
                    {
                        if (lst[i] == -1)
                        {
                            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(255, 77, 59);
                        }
                        else
                        {
                            c.RectColor = Color.FromArgb(223, 223, 223);
                        }
                    }
                }
                ShowBtn(PageIndex > 1, PageIndex < PageCount);
            }
            finally
            {
                ControlHelper.FreezeControl(tableLayoutPanel1, false);
            }
        }

跳转页面

private void page_BtnClick(object sender, EventArgs e)
        {
            PageIndex = (sender as UCBtnExt).BtnText.ToInt();
            StartIndex = (PageIndex - 1) * 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 - 1) * 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 = 0;
        public override int PageSize
        {
            get
            {
                return m_intPageSize;
            }
            set
            {
                m_intPageSize = value;
                ResetPageCount();
            }
        }

        public override void FirstPage()
        {
            if (PageIndex == 1)
                return;
            PageIndex = 1;
            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        public override void PreviousPage()
        {
            if (PageIndex <= 1)
            {
                return;
            }
            PageIndex--;

            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        public override void NextPage()
        {
            if (PageIndex >= PageCount)
            {
                return;
            }
            PageIndex++;
            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        public override void EndPage()
        {
            if (PageIndex == PageCount)
                return;
            PageIndex = PageCount;
            StartIndex = (PageIndex - 1) * PageSize;
            ReloadPage();
            var s = GetCurrentSource();
            if (ShowSourceChanged != null)
            {
                ShowSourceChanged(s);
            }
        }

        private void ResetPageCount()
        {
            if (PageSize > 0)
            {
                PageCount = m_dataSource.Count / m_intPageSize + (m_dataSource.Count % m_intPageSize > 0 ? 1 : 0);
            }
            txtPage.MaxValue = PageCount;
            txtPage.MinValue = 1;
            ReloadPage();
        }

        private void ReloadPage()
        {
            try
            {
                ControlHelper.FreezeControl(tableLayoutPanel1, true);
                List<int> lst = new List<int>();

                if (PageCount <= 9)
                {
                    for (var i = 1; i <= PageCount; i++)
                    {
                        lst.Add(i);
                    }
                }
                else
                {
                    if (this.PageIndex <= 6)
                    {
                        for (var i = 1; i <= 7; i++)
                        {
                            lst.Add(i);
                        }
                        lst.Add(-1);
                        lst.Add(PageCount);
                    }
                    else if (this.PageIndex > PageCount - 6)
                    {
                        lst.Add(1);
                        lst.Add(-1);
                        for (var i = PageCount - 6; i <= PageCount; i++)
                        {
                            lst.Add(i);
                        }
                    }
                    else
                    {
                        lst.Add(1);
                        lst.Add(-1);
                        var begin = PageIndex - 2;
                        var end = PageIndex + 2;
                        if (end > PageCount)
                        {
                            end = PageCount;
                            begin = end - 4;
                            if (PageIndex - begin < 2)
                            {
                                begin = begin - 1;
                            }
                        }
                        else if (end + 1 == PageCount)
                        {
                            end = PageCount;
                        }
                        for (var i = begin; i <= end; i++)
                        {
                            lst.Add(i);
                        }
                        if (end != PageCount)
                        {
                            lst.Add(-1);
                            lst.Add(PageCount);
                        }
                    }
                }

                for (int i = 0; i < 9; i++)
                {
                    UCBtnExt c = (UCBtnExt)this.tableLayoutPanel1.Controls.Find("p" + (i + 1), false)[0];
                    if (i >= lst.Count)
                    {
                        c.Visible = false;
                    }
                    else
                    {
                        if (lst[i] == -1)
                        {
                            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(255, 77, 59);
                        }
                        else
                        {
                            c.RectColor = Color.FromArgb(223, 223, 223);
                        }
                    }
                }
                ShowBtn(PageIndex > 1, PageIndex < PageCount);
            }
            finally
            {
                ControlHelper.FreezeControl(tableLayoutPanel1, false);
            }
        }

        private void page_BtnClick(object sender, EventArgs e)
        {
            PageIndex = (sender as UCBtnExt).BtnText.ToInt();
            StartIndex = (PageIndex - 1) * 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 - 1) * 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 = 5;
            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(5, 5);
            this.btnFirst.Margin = new System.Windows.Forms.Padding(5);
            this.btnFirst.Name = "btnFirst";
            this.btnFirst.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.btnFirst.RectWidth = 1;
            this.btnFirst.Size = new System.Drawing.Size(30, 30);
            this.btnFirst.TabIndex = 0;
            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 = 5;
            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(45, 5);
            this.btnPrevious.Margin = new System.Windows.Forms.Padding(5);
            this.btnPrevious.Name = "btnPrevious";
            this.btnPrevious.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.btnPrevious.RectWidth = 1;
            this.btnPrevious.Size = new System.Drawing.Size(30, 30);
            this.btnPrevious.TabIndex = 1;
            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 = 15;
            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, 10, 0);
            this.tableLayoutPanel1.Controls.Add(this.p1, 2, 0);
            this.tableLayoutPanel1.Controls.Add(this.btnToPage, 14, 0);
            this.tableLayoutPanel1.Controls.Add(this.btnEnd, 12, 0);
            this.tableLayoutPanel1.Controls.Add(this.btnNext, 11, 0);
            this.tableLayoutPanel1.Controls.Add(this.p8, 9, 0);
            this.tableLayoutPanel1.Controls.Add(this.p7, 8, 0);
            this.tableLayoutPanel1.Controls.Add(this.p6, 7, 0);
            this.tableLayoutPanel1.Controls.Add(this.p5, 6, 0);
            this.tableLayoutPanel1.Controls.Add(this.p4, 5, 0);
            this.tableLayoutPanel1.Controls.Add(this.p3, 4, 0);
            this.tableLayoutPanel1.Controls.Add(this.p2, 3, 0);
            this.tableLayoutPanel1.Controls.Add(this.btnPrevious, 1, 0);
            this.tableLayoutPanel1.Controls.Add(this.btnFirst, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.txtPage, 13, 0);
            this.tableLayoutPanel1.Location = new System.Drawing.Point(129, 0);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 1;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(662, 40);
            this.tableLayoutPanel1.TabIndex = 1;
            // 
            // 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 = "9";
            this.p9.ConerRadius = 5;
            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(402, 5);
            this.p9.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p9.Name = "p9";
            this.p9.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p9.RectWidth = 1;
            this.p9.Size = new System.Drawing.Size(36, 30);
            this.p9.TabIndex = 17;
            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 = "1";
            this.p1.ConerRadius = 5;
            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(82, 5);
            this.p1.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p1.Name = "p1";
            this.p1.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p1.RectWidth = 1;
            this.p1.Size = new System.Drawing.Size(36, 30);
            this.p1.TabIndex = 16;
            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 = 5;
            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(595, 5);
            this.btnToPage.Margin = new System.Windows.Forms.Padding(5);
            this.btnToPage.Name = "btnToPage";
            this.btnToPage.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.btnToPage.RectWidth = 1;
            this.btnToPage.Size = new System.Drawing.Size(62, 30);
            this.btnToPage.TabIndex = 15;
            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 = 5;
            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(485, 5);
            this.btnEnd.Margin = new System.Windows.Forms.Padding(5);
            this.btnEnd.Name = "btnEnd";
            this.btnEnd.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.btnEnd.RectWidth = 1;
            this.btnEnd.Size = new System.Drawing.Size(30, 30);
            this.btnEnd.TabIndex = 13;
            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 = 5;
            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(445, 5);
            this.btnNext.Margin = new System.Windows.Forms.Padding(5);
            this.btnNext.Name = "btnNext";
            this.btnNext.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.btnNext.RectWidth = 1;
            this.btnNext.Size = new System.Drawing.Size(30, 30);
            this.btnNext.TabIndex = 12;
            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 = "8";
            this.p8.ConerRadius = 5;
            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(362, 5);
            this.p8.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p8.Name = "p8";
            this.p8.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p8.RectWidth = 1;
            this.p8.Size = new System.Drawing.Size(36, 30);
            this.p8.TabIndex = 8;
            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 = "7";
            this.p7.ConerRadius = 5;
            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(322, 5);
            this.p7.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p7.Name = "p7";
            this.p7.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p7.RectWidth = 1;
            this.p7.Size = new System.Drawing.Size(36, 30);
            this.p7.TabIndex = 7;
            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 = "6";
            this.p6.ConerRadius = 5;
            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(282, 5);
            this.p6.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p6.Name = "p6";
            this.p6.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p6.RectWidth = 1;
            this.p6.Size = new System.Drawing.Size(36, 30);
            this.p6.TabIndex = 6;
            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 = "5";
            this.p5.ConerRadius = 5;
            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(242, 5);
            this.p5.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p5.Name = "p5";
            this.p5.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p5.RectWidth = 1;
            this.p5.Size = new System.Drawing.Size(36, 30);
            this.p5.TabIndex = 5;
            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 = "4";
            this.p4.ConerRadius = 5;
            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(202, 5);
            this.p4.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p4.Name = "p4";
            this.p4.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p4.RectWidth = 1;
            this.p4.Size = new System.Drawing.Size(36, 30);
            this.p4.TabIndex = 4;
            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 = "3";
            this.p3.ConerRadius = 5;
            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(162, 5);
            this.p3.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p3.Name = "p3";
            this.p3.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p3.RectWidth = 1;
            this.p3.Size = new System.Drawing.Size(36, 30);
            this.p3.TabIndex = 3;
            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 = "2";
            this.p2.ConerRadius = 5;
            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(122, 5);
            this.p2.Margin = new System.Windows.Forms.Padding(2, 5, 2, 5);
            this.p2.Name = "p2";
            this.p2.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223)))));
            this.p2.RectWidth = 1;
            this.p2.Size = new System.Drawing.Size(36, 30);
            this.p2.TabIndex = 2;
            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 = 5;
            this.txtPage.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.txtPage.DecLength = 2;
            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(524, 5);
            this.txtPage.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.txtPage.MaxValue = new decimal(new int[] {
            1000000,
            0,
            0,
            0});
            this.txtPage.MinValue = new decimal(new int[] {
            1000000,
            0,
            0,
            -2147483648});
            this.txtPage.Name = "txtPage";
            this.txtPage.Padding = new System.Windows.Forms.Padding(5);
            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)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
            this.txtPage.RectWidth = 1;
            this.txtPage.RegexPattern = "";
            this.txtPage.Size = new System.Drawing.Size(62, 30);
            this.txtPage.TabIndex = 14;
            // 
            // 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(921, 41);
            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 点个星 星吧

作者:冰封一夏
出处: http://www.hzhcontrols.com/doc.html
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

原文出处:冰封一夏

原文链接:https://www.cnblogs.com/bfyx/p/11363075.html

本文观点不代表Dotnet9立场,转载请联系原作者。

发表评论

登录后才能评论