public partial class UserControl1 : UserControl
    {
        //定义的分页事件
        public event EventHandler PageChanged;        
        private int _PageIndex;
        public int PageIndex
        {
            get { return _PageIndex; }
            set
            {
                if (value < 1)
                {
                    value = 1;
                }
                if (value>PageCount)
                {
                    value = PageCount;
                }
                _PageIndex = value;
                this.textBox1.Text = _PageIndex.ToString();               
                 //判断事件是否为空
                if (PageChanged != null)
                {
                    PageChanged(this, null);
                }
            }
        }
        public int PageCount { get; set; }
        
        public UserControl1()
        {
            InitializeComponent();           
             PageIndex = 1;
            PageCount = 10;
            this.textBox1.Text = PageIndex.ToString();
        }       
         private void button1_Click(object sender, EventArgs e)
        {
            PageIndex = 1;
        }      
         private void button2_Click(object sender, EventArgs e)
        {
            PageIndex--;
        }        
        private void button3_Click(object sender, EventArgs e)
        {
            PageIndex++;
        }       
         private void button4_Click(object sender, EventArgs e)
        {
            PageIndex = PageCount;
        }
    }
posted on 2019-10-19 11:40  .net之路  阅读(66)  评论(0编辑  收藏  举报