为winform应用程序开发寻呼机c# [英] Developing pager for winform application c#

查看:49
本文介绍了为winform应用程序开发寻呼机c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



$
我首先搜索谷歌获取任何现成的数字寻呼机样本以获取胜利形式但不幸的是我没有找到。许多存在用于Web应用程序。所以我决定发展自己的。我有一个用户控件,我想在运行时在用户控件
上添加一些标签来模拟数字寻呼机链接。



喜欢<< ; < 1 2 3 4 5> >>
$


这里是我的代码到目前为止


公共部分类PagerBar:UserControl

    {

        public PagerBar()

        {

            InitializeComponent();

        }


        int totalrecords = 0;

        public int TotalRecords

        {

           得到{return totalrecords; }
           设置{totalrecords = value; }
        }


        int recordsperpage = 0;

        public int RecordsPerPage

        {

           得到{return recordsperpage; }
           设置{recordsperpage = value; }
        }


        int curpage = 0;

        public int CurrentPage

        {

           得到{return curpage; }
           设置{curpage = value; }
        }


        int maxpagerlink = 0;

        public int MaxPagerLink

        {

            get {return maxpagerlink; }
           设置{maxpagerlink = value; }
        }


        public bool HasPreviousPage

        {

           得到
            {

                return(CurrentPage> 1);

            }
        }


        ///< summary>

        ///获取下一页的布尔值

        ///< / summary>

        public bool HasNextPage

        {

           得到
            {

                return(CurrentPage + 1< = RecordsPerPage);

            }
        }


        int pagecount = 0;

        public int PageCount

        {

           得到
            {

                pagecount = TotalRecords> 0? (int)Math.Ceiling(TotalRecords /(double)RecordsPerPage):0;

              ;&NBSP;&NBSP; return pagecount;


            }


        }


        public void BuildPager(int CurrentPage)

        {

            if(CurrentPage> = MaxPagerLink)

            {
$


            }
           否则为
            {
$


            }
        }
    }


我的第一个上一个,下一个& prev按钮将被修复。我不会在运行时生成这些按钮。我想在用户控制的运行时只生成像1 2 3 4 5等数字链接。



有一件事我需要修复那个寻呼机条的数量是在我的情况下固定,即5.我想显示总是5个寻呼机链接,如1 2 3 4 5或6 7 8 9 10等。



假设总数记录是36,我希望每页显示10条记录,因此我需要在运行时生成4个寻呼机链接。如果记录数为110则应该正确处理所有内容,我认为正确的逻辑不会以这种方式生成寻呼机链接。
如果总记录为110且每页记录为10,则总页面栏应为11但我想一次只显示5个。第一次1 2 3 4 5当用户点击第5个寻呼机栏并且下次点击下一个按钮然后寻呼机链接将是6 7 8 9 10.这样
i想要显示寻呼机链接但是正确的逻辑不会来介意生成我想显示寻呼机链接的方式。如果有人帮我总是处理5个寻呼机链接的生成,那将会很有帮助。

解决方案

使用系统;

使用System.Collections.Generic;

使用System.ComponentModel;

使用System.Drawing;

使用System.Data;

使用System.Text;

使用System.Windows.Forms;



命名空间PagerControl

{

   公共部分类BBAPager:UserControl

    {

        #region本地变量声明

        private int MaxNumberofButtonsToShow = 0;



        private int TotalRecords = 0;

        private int __CurrentPage = 0;

        int CurrentWidth;

        int __StartWidth;

        int __CurrentBlock = 0;

        int __ActivePage = 0;

        #endregion



        #region代表

        public delegate void PageClick(object sender,PageClickEventHandler e);

        #endregion



        #region事件声明

       公共活动PageClick PageClicked;

        #endregion



        #region财产声明

        #region Properties

        [CategoryAttribute(" Paging Attributes"),DescriptionAttribute(" No of Records")]¥b $ b        public int RecordCount

        {

           得到{return TotalRecords; }


           设置{TotalRecords = value; }
        }


        [CategoryAttribute(" Paging Attributes"),DescriptionAttribute(" Active Page")] zh
        public int ActivePage

        {

            get {return __ActivePage; }
        }


        [CategoryAttribute(" Paging Attributes"),DescriptionAttribute(" No of Page Links to display to);)
        public int CurrentPage

        {

            get {return __CurrentPage; }
        }


        [CategoryAttribute(" Paging Attributes"),DescriptionAttribute(" No of Page Links to display to);)
        public int MaximumNumberofLinks

        {

            get {return MaxNumberofButtonsToShow; }


           设置{MaxNumberofButtonsToShow = value; OnDisplaySizeChanged(当前页); }
        }


        private int GetCurrentBlock(int PageNo)

        {

            int curBlock = 0;



            while(!PageInBlock(curBlock,PageNo))
$
                curBlock ++;
$


            return curBlock;

        }
        #endregion



        #region方法

        #region当前页面中的当前页面为
        private bool PageInBlock(int Block,int PageNo)

        {

            bool retVal = false;

            int startPg,endPg;

            startPg = Block * MaximumNumberofLinks + 1;

            endPg = startPg + MaximumNumberofLinks - 1;

            if(endPg> RecordCount)

                endPg = RecordCount;



           如果(您做生意> = startPg&安培;&安培;您做生意< = endPg)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; retVal = true;



            return retVal;

        }
        #endregion



        #region重置面板

        private void ResetPanel()

        {

            this.pnlLink.SuspendLayout();

            this.SuspendLayout();
$


            this.Controls.Remove(pnlLink);

            pnlLink = new Panel();

            this.pnlLink.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;



          &NBSP;&NBSP; this.pnlLink.Dock = System.Windows.Forms.DockStyle.Fill;

            this.pnlLink.Location = new System.Drawing.Point(0,0);

            this.pnlLink.Name =" pnlLink";

            this.pnlLink.Size = new System.Drawing.Size(919,28);

            this.pnlLink.TabIndex = 0;



            this.Controls.Add(this.pnlLink);
$


            this.pnlLink.ResumeLayout(false);

            this.pnlLink.PerformLayout();

            this.ResumeLayout(false);

        }
        #endregion



        #region页面标签

        private System.Windows.Forms.Label GetNewLabel(System.Drawing.Point PT,int Page)

        {

            System.Windows.Forms.Label lnkLbl;

            lnkLbl = new System.Windows.Forms.Label();

            lnkLbl.AutoSize = true;

            lnkLbl.Location = PT;



            lnkLbl.Size = new System.Drawing.Size(13,13);

            lnkLbl.TabIndex = 0;

            lnkLbl.TabStop = true;

            lnkLbl.Text = Page.ToString();

            lnkLbl.Cursor = System.Windows.Forms.Cursors.Hand;

            if(Page == ActivePage)

                lnkLbl.ForeColor = System.Drawing.Color.Red;

           否则b $ b                lnkLbl.ForeColor = System.Drawing.Color.Blue;

            lnkLbl.Click + =新的EventHandler(this.lnkLbl_LinkClicked);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; return lnkLbl;

        }
        #endregion



        #region添加上一个和下一个标签

        private System.Windows.Forms.Label GetNewLabel(System.Drawing.Point PT,bool PrintNext)

        {

            System.Windows.Forms.Label lnkLbl;

            lnkLbl = new System.Windows.Forms.Label();

            lnkLbl.Cursor = System.Windows.Forms.Cursors.Hand;

            lnkLbl.AutoSize = true;

            lnkLbl.Location = PT;

            lnkLbl.AutoSize = false;

            lnkLbl.Size = new System.Drawing.Size(16,16);

            lnkLbl.TabIndex = 0;

            lnkLbl.TabStop = true;

            if(PrintNext)

            {

                lnkLbl.Image =全​​球:: PagerControl.Properties.Resources.Next;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; lnkLbl.ImageAlign = ContentAlignment.TopCenter;

                lnkLbl.Click + = new EventHandler(this.lnkLbl_LinkNext);

            }
           否则为
            {

                lnkLbl.Image =全​​球:: PagerControl.Properties.Resources.Previous;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; lnkLbl.ImageAlign = ContentAlignment.TopCenter;

                lnkLbl.Click + = new EventHandler(this.lnkLbl_LinkPrev);

            }
            return lnkLbl;

        }
        #endregion



        #region添加上一个和下一个标签

        private System.Windows.Forms.Label GetNewTLabel(System.Drawing.Point PT,bool PrintNext)

        {

            System.Windows.Forms.Label lnkLbl;

            lnkLbl = new System.Windows.Forms.Label();

            lnkLbl.Cursor = System.Windows.Forms.Cursors.Hand;

            lnkLbl.AutoSize = true;

            lnkLbl.Location = PT;

            lnkLbl.AutoSize = false;

            lnkLbl.Size = new System.Drawing.Size(16,16);

            lnkLbl.TabIndex = 0;

            lnkLbl.TabStop = true;

            if(PrintNext)

            {

                lnkLbl.Image =全​​球:: PagerControl.Properties.Resources.Last;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; lnkLbl.ImageAlign = ContentAlignment.TopCenter;

                lnkLbl.Click + = new EventHandler(this.lnkLbl_LinkLast);

            }
           否则为
            {

                lnkLbl.Image =全​​球:: PagerControl.Properties.Resources.First;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; lnkLbl.ImageAlign = ContentAlignment.TopCenter;

                lnkLbl.Click + = new EventHandler(this.lnkLbl_LinkFirst);

            }
            return lnkLbl;

        }
        #endregion



        #region Control Resize

        private void OnDisplaySizeChanged(int PageNo)

        {

            int StartFrom,CurrentBlock;

            int TotalLinks;

            if(MaximumNumberofLinks == 0 || MaximumNumberofLinks> RecordCount)返回;

            ResetPanel();

            CurrentBlock = GetCurrentBlock(PageNo);

            int startpg,endPg;



            startpg = CurrentBlock * MaximumNumberofLinks + 1;

            endPg = startpg + MaximumNumberofLinks - 1;

$




      &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; bool PrintNext = false;



            if(endPg> = RecordCount)

            {

                endPg = RecordCount;

                TotalLinks = RecordCount - startpg + 1;

                __StartWidth = CurrentWidth - ((TotalLinks + 1)* 16);

            }
           否则为
            {

                TotalLinks = MaximumNumberofLinks + 3;

                __StartWidth = CurrentWidth - (TotalLinks * 16);

                PrintNext = true;

            }


            StartFrom = __StartWidth;

            for(int lblCnt = startpg - 1; lblCnt< endPg; lblCnt ++)

            {

                this.pnlLink.Controls.Add(GetNewLabel(new Point(StartFrom,6),lblCnt + 1));
$
          &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; StartFrom + = 16;

            }
            if(PrintNext)

            {

                this.pnlLink.Controls.Add(GetNewLabel(new Point(StartFrom,6),true));
$
           &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; StartFrom + = 16;

                this.pnlLink.Controls.Add(GetNewTLabel(new Point(StartFrom,6),true));
$
           &NBSP; }
            if(__ CurrentPage> MaximumNumberofLinks)

            {

                this.pnlLink.Controls.Add(GetNewLabel(new Point(__ StartWidth - 16,6),false));
$
          &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.pnlLink.Controls.Add(GetNewTLabel(new Point(__ StartWidth - 32,6),false));
$
          &NBSP;&NBSP; }
        }
        #endregion

        #endregion

        #endregion



        #region构造函数

       公共BBAPager()

        {

            InitializeComponent();

            CurrentWidth = this.Width;

            __CurrentPage = 1;

            __ActivePage = 1;

        }
        #endregion



        private void lnkLbl_LinkClicked(object sender,EventArgs e)

        {
$


            __CurrentPage = Convert.ToInt32(((Label)sender).Text);

            __ActivePage = __CurrentPage;

            OnDisplaySizeChanged(__ CurrentPage);

            PageClicked(发件人,新的PageClickEventHandler(__ ActivePage));
$
        }


        private void lnkLbl_LinkNext(object sender,EventArgs e)

        {

            int CurrentBlock;

            int startpg,endPg;

            CurrentBlock = GetCurrentBlock(CurrentPage);
$


            startpg = CurrentBlock * MaximumNumberofLinks + 1;

            endPg = startpg + MaximumNumberofLinks - 1;

            __CurrentPage = ++ endPg;

            OnDisplaySizeChanged(CurrentPage);

        }


        private void lnkLbl_LinkLast(object sender,EventArgs e)

        {

            int CurrentBlock;

            int startpg,endPg;

            CurrentBlock = GetCurrentBlock(RecordCount);
$


            startpg = CurrentBlock * MaximumNumberofLinks + 1;

            endPg = startpg + MaximumNumberofLinks - 1;

            __CurrentPage = startpg;

            OnDisplaySizeChanged(CurrentPage);

        }


        private void lnkLbl_LinkPrev(object sender,EventArgs e)

        {

            int CurrentBlock;

            int startpg;

            CurrentBlock = GetCurrentBlock(CurrentPage);
$


            startpg = CurrentBlock * MaximumNumberofLinks + 1;

            __CurrentPage = --startpg;

            OnDisplaySizeChanged(CurrentPage);

        }


        private void lnkLbl_LinkFirst(object sender,EventArgs e)

        {

            __CurrentPage = 1;

            OnDisplaySizeChanged(CurrentPage);

        }


        private void BBAPager_SizeChanged(object sender,EventArgs e)

        {

            CurrentWidth = this.Width;

        }


        private void BBAPager_Load(object sender,EventArgs e)

        {

             CurrentWidth = this.Width;

             OnDisplaySizeChanged(CurrentPage);

        }
    }




    #region自定义事件

   公共类PageClickEventHandler:EventArgs

    {

        private int __Page = 0;



        #region财产声明

        public int SelectedPage

        {

            get {return __Page; }
        }
        #endregion



        #region构造函数

        public PageClickEventHandler(int Page)

        {

            __Page = Page;

        }
        #endregion

    }
    #endregion

}


这种方式叫做


============ =======


将寻呼机控件拖到表单上并设置一些属性,如下面的


 公共部分类Form1 :表格

    {

        public Form1()

        {

            InitializeComponent();

            bbaPager1.RecordCount = 53;

            bbaPager1.MaximumNumberofLinks = 5;

            bbaPager1.PageClicked + = new PagerControl.BBAPager.PageClick(bbaPager1_PageClicked);

        }


        void bbaPager1_PageClicked(object sender,PagerControl.PageClickEventHandler e)

        {

            MessageBox.Show(" Page" + e.SelectedPage.ToString());

        }
    }




       ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;



i search google first to get any ready made sample for numeric pager for win form but unfortunately i found none. many exist for web application. so i have decided to develop my own. i have take one user control and i want to add some label on the user control at run time for simulating numeric pager link.

like << < 1 2 3 4 5 > >>

here is my code so far

public partial class PagerBar : UserControl
    {
        public PagerBar()
        {
            InitializeComponent();
        }

        int totalrecords = 0;
        public int TotalRecords
        {
            get { return totalrecords; }
            set { totalrecords = value; }
        }

        int recordsperpage = 0;
        public int RecordsPerPage
        {
            get { return recordsperpage; }
            set { recordsperpage = value; }
        }

        int curpage = 0;
        public int CurrentPage
        {
            get { return curpage; }
            set { curpage = value; }
        }

        int maxpagerlink = 0;
        public int MaxPagerLink
        {
            get { return maxpagerlink; }
            set { maxpagerlink = value; }
        }

        public bool HasPreviousPage
        {
            get
            {
                return (CurrentPage > 1);
            }
        }

        /// <summary>
        /// Gets the boolean value of next page
        /// </summary>
        public bool HasNextPage
        {
            get
            {
                return (CurrentPage + 1 <= RecordsPerPage);
            }
        }

        int pagecount = 0;
        public int PageCount
        {
            get
            {
                pagecount = TotalRecords > 0 ? (int)Math.Ceiling(TotalRecords / (double)RecordsPerPage) : 0;
                return pagecount;
            }

        }

        public void BuildPager(int CurrentPage)
        {
            if (CurrentPage >= MaxPagerLink)
            {

            }
            else
            {

            }
        }
    }

my first prev,next & prev button will be fixed. i will not generate these button at run time. i want to generate only numeric link like 1 2 3 4 5 etc at run time on user control.

one thing i need to fix that number of pager bar is will be fixed in my case and that is 5. i want to show always 5 pager link like 1 2 3 4 5 or 6 7 8 9 10 etc.

suppose total records is 36 and i want to show 10 records per page so 4 pager link i need to generate at run time. the right logic is not coming to my mind to generate pager link in such a way if number of records is 110 then everything should be handle properly. if total records is 110 and records per page is 10 then total pager bar should be 11 but i want to show only 5 at a time. first time 1 2 3 4 5 when user click on 5th pager bar and next time click on next button then pager link will be 6 7 8 9 10. this way i want to show pager link but right logic is not coming to mind to generate the way i want to display pager link. it will be great help if some one help me to handle generation of 5 pager link always.

解决方案

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace PagerControl
{
    public partial class BBAPager : UserControl
    {
        #region Local variable Declarations
        private int MaxNumberofButtonsToShow = 0;

        private int TotalRecords = 0;
        private int __CurrentPage = 0;
        int CurrentWidth;
        int __StartWidth;
        int __CurrentBlock = 0;
        int __ActivePage = 0;
        #endregion

        #region Delegates
        public delegate void PageClick(object sender, PageClickEventHandler e);
        #endregion

        #region Event Declarations
        public event PageClick PageClicked;
        #endregion

        #region Property Declarations
        #region Properties
        [CategoryAttribute("Paging Attributes"), DescriptionAttribute("No of Records")]
        public int RecordCount
        {
            get { return TotalRecords; }

            set { TotalRecords = value; }
        }

        [CategoryAttribute("Paging Attributes"), DescriptionAttribute("Active Page")]
        public int ActivePage
        {
            get { return __ActivePage; }
        }

        [CategoryAttribute("Paging Attributes"), DescriptionAttribute("No of Page Links to Display")]
        public int CurrentPage
        {
            get { return __CurrentPage; }
        }

        [CategoryAttribute("Paging Attributes"), DescriptionAttribute("No of Page Links to Display")]
        public int MaximumNumberofLinks
        {
            get { return MaxNumberofButtonsToShow; }

            set { MaxNumberofButtonsToShow = value; OnDisplaySizeChanged(CurrentPage); }
        }

        private int GetCurrentBlock(int PageNo)
        {
            int curBlock = 0;

            while (!PageInBlock(curBlock, PageNo))
                curBlock++;

            return curBlock;
        }
        #endregion

        #region Methods
        #region Current Page in Block
        private bool PageInBlock(int Block, int PageNo)
        {
            bool retVal = false;
            int startPg, endPg;
            startPg = Block * MaximumNumberofLinks + 1;
            endPg = startPg + MaximumNumberofLinks - 1;
            if (endPg > RecordCount)
                endPg = RecordCount;

            if (PageNo >= startPg && PageNo <= endPg)
                retVal = true;

            return retVal;
        }
        #endregion

        #region Reset Panel
        private void ResetPanel()
        {
            this.pnlLink.SuspendLayout();
            this.SuspendLayout();

            this.Controls.Remove(pnlLink);
            pnlLink = new Panel();
            this.pnlLink.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

            this.pnlLink.Dock = System.Windows.Forms.DockStyle.Fill;
            this.pnlLink.Location = new System.Drawing.Point(0, 0);
            this.pnlLink.Name = "pnlLink";
            this.pnlLink.Size = new System.Drawing.Size(919, 28);
            this.pnlLink.TabIndex = 0;

            this.Controls.Add(this.pnlLink);

            this.pnlLink.ResumeLayout(false);
            this.pnlLink.PerformLayout();
            this.ResumeLayout(false);
        }
        #endregion

        #region Page Labels
        private System.Windows.Forms.Label GetNewLabel(System.Drawing.Point PT, int Page)
        {
            System.Windows.Forms.Label lnkLbl;
            lnkLbl = new System.Windows.Forms.Label();
            lnkLbl.AutoSize = true;
            lnkLbl.Location = PT;

            lnkLbl.Size = new System.Drawing.Size(13, 13);
            lnkLbl.TabIndex = 0;
            lnkLbl.TabStop = true;
            lnkLbl.Text = Page.ToString();
            lnkLbl.Cursor = System.Windows.Forms.Cursors.Hand;
            if (Page == ActivePage)
                lnkLbl.ForeColor = System.Drawing.Color.Red;
            else
                lnkLbl.ForeColor = System.Drawing.Color.Blue;
            lnkLbl.Click += new EventHandler(this.lnkLbl_LinkClicked);

            return lnkLbl;
        }
        #endregion

        #region Add Previous and Next Labels
        private System.Windows.Forms.Label GetNewLabel(System.Drawing.Point PT, bool PrintNext)
        {
            System.Windows.Forms.Label lnkLbl;
            lnkLbl = new System.Windows.Forms.Label();
            lnkLbl.Cursor = System.Windows.Forms.Cursors.Hand;
            lnkLbl.AutoSize = true;
            lnkLbl.Location = PT;
            lnkLbl.AutoSize = false;
            lnkLbl.Size = new System.Drawing.Size(16, 16);
            lnkLbl.TabIndex = 0;
            lnkLbl.TabStop = true;
            if (PrintNext)
            {
                lnkLbl.Image = global::PagerControl.Properties.Resources.Next;
                lnkLbl.ImageAlign = ContentAlignment.TopCenter;
                lnkLbl.Click += new EventHandler(this.lnkLbl_LinkNext);
            }
            else
            {
                lnkLbl.Image = global::PagerControl.Properties.Resources.Previous;
                lnkLbl.ImageAlign = ContentAlignment.TopCenter;
                lnkLbl.Click += new EventHandler(this.lnkLbl_LinkPrev);
            }
            return lnkLbl;
        }
        #endregion

        #region Add Previous and Next Labels
        private System.Windows.Forms.Label GetNewTLabel(System.Drawing.Point PT, bool PrintNext)
        {
            System.Windows.Forms.Label lnkLbl;
            lnkLbl = new System.Windows.Forms.Label();
            lnkLbl.Cursor = System.Windows.Forms.Cursors.Hand;
            lnkLbl.AutoSize = true;
            lnkLbl.Location = PT;
            lnkLbl.AutoSize = false;
            lnkLbl.Size = new System.Drawing.Size(16, 16);
            lnkLbl.TabIndex = 0;
            lnkLbl.TabStop = true;
            if (PrintNext)
            {
                lnkLbl.Image = global::PagerControl.Properties.Resources.Last;
                lnkLbl.ImageAlign = ContentAlignment.TopCenter;
                lnkLbl.Click += new EventHandler(this.lnkLbl_LinkLast);
            }
            else
            {
                lnkLbl.Image = global::PagerControl.Properties.Resources.First;
                lnkLbl.ImageAlign = ContentAlignment.TopCenter;
                lnkLbl.Click += new EventHandler(this.lnkLbl_LinkFirst);
            }
            return lnkLbl;
        }
        #endregion

        #region Control Resize
        private void OnDisplaySizeChanged(int PageNo)
        {
            int StartFrom, CurrentBlock;
            int TotalLinks;
            if (MaximumNumberofLinks==0 || MaximumNumberofLinks > RecordCount) return;
            ResetPanel();
            CurrentBlock = GetCurrentBlock(PageNo);
            int startpg, endPg;

            startpg = CurrentBlock * MaximumNumberofLinks + 1;
            endPg = startpg + MaximumNumberofLinks - 1;



            bool PrintNext = false;

            if (endPg >= RecordCount)
            {
                endPg = RecordCount;
                TotalLinks = RecordCount - startpg + 1;
                __StartWidth = CurrentWidth - ((TotalLinks + 1) * 16);
            }
            else
            {
                TotalLinks = MaximumNumberofLinks + 3;
                __StartWidth = CurrentWidth - (TotalLinks * 16);
                PrintNext = true;
            }

            StartFrom = __StartWidth;
            for (int lblCnt = startpg - 1; lblCnt < endPg; lblCnt++)
            {
                this.pnlLink.Controls.Add(GetNewLabel(new Point(StartFrom, 6), lblCnt + 1));
                StartFrom += 16;
            }
            if (PrintNext)
            {
                this.pnlLink.Controls.Add(GetNewLabel(new Point(StartFrom, 6), true));
                StartFrom += 16;
                this.pnlLink.Controls.Add(GetNewTLabel(new Point(StartFrom, 6), true));
            }
            if (__CurrentPage > MaximumNumberofLinks)
            {
                this.pnlLink.Controls.Add(GetNewLabel(new Point(__StartWidth - 16, 6), false));
                this.pnlLink.Controls.Add(GetNewTLabel(new Point(__StartWidth - 32, 6), false));
            }
        }
        #endregion
        #endregion
        #endregion

        #region Constructor
        public BBAPager()
        {
            InitializeComponent();
            CurrentWidth = this.Width;
            __CurrentPage = 1;
            __ActivePage = 1;
        }
        #endregion

        private void lnkLbl_LinkClicked(object sender, EventArgs e)
        {

            __CurrentPage = Convert.ToInt32(((Label)sender).Text);
            __ActivePage = __CurrentPage;
            OnDisplaySizeChanged(__CurrentPage);
            PageClicked(sender, new PageClickEventHandler(__ActivePage));
        }

        private void lnkLbl_LinkNext(object sender, EventArgs e)
        {
            int CurrentBlock;
            int startpg, endPg;
            CurrentBlock = GetCurrentBlock(CurrentPage);

            startpg = CurrentBlock * MaximumNumberofLinks + 1;
            endPg = startpg + MaximumNumberofLinks - 1;
            __CurrentPage = ++endPg;
            OnDisplaySizeChanged(CurrentPage);
        }

        private void lnkLbl_LinkLast(object sender, EventArgs e)
        {
            int CurrentBlock;
            int startpg, endPg;
            CurrentBlock = GetCurrentBlock(RecordCount);

            startpg = CurrentBlock * MaximumNumberofLinks + 1;
            endPg = startpg + MaximumNumberofLinks - 1;
            __CurrentPage = startpg;
            OnDisplaySizeChanged(CurrentPage);
        }

        private void lnkLbl_LinkPrev(object sender, EventArgs e)
        {
            int CurrentBlock;
            int startpg;
            CurrentBlock = GetCurrentBlock(CurrentPage);

            startpg = CurrentBlock * MaximumNumberofLinks + 1;
            __CurrentPage = --startpg;
            OnDisplaySizeChanged(CurrentPage);
        }

        private void lnkLbl_LinkFirst(object sender, EventArgs e)
        {
            __CurrentPage = 1;
            OnDisplaySizeChanged(CurrentPage);
        }

        private void BBAPager_SizeChanged(object sender, EventArgs e)
        {
            CurrentWidth = this.Width;
        }

        private void BBAPager_Load(object sender, EventArgs e)
        {
             CurrentWidth = this.Width;
             OnDisplaySizeChanged(CurrentPage);
        }
    }


    #region Custom Events
    public class PageClickEventHandler : EventArgs
    {
        private int __Page = 0;

        #region Property Declarations
        public int SelectedPage
        {
            get { return __Page; }
        }
        #endregion

        #region Constructor
        public PageClickEventHandler(int Page)
        {
            __Page = Page;
        }
        #endregion
    }
    #endregion
}

this way it is called

===================

Drag the pager control on to the form and set some properties like below one

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            bbaPager1.RecordCount = 53;
            bbaPager1.MaximumNumberofLinks = 5;
            bbaPager1.PageClicked += new PagerControl.BBAPager.PageClick(bbaPager1_PageClicked);
        }

        void bbaPager1_PageClicked(object sender, PagerControl.PageClickEventHandler e)
        {
            MessageBox.Show("Page " + e.SelectedPage.ToString());
        }
    }

                        


这篇关于为winform应用程序开发寻呼机c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆