Пример #1
0
        /// <summary>
        /// 创建分页数字按钮
        /// </summary>
        private void BuildPageControl()
        {
            int x = 0;//按钮横坐标
            int num = 0;//按钮数
            for (int i = GroupSize * (CurrentGroup - 1); i < GroupSize * CurrentGroup; i++)
            {
                if (i + 1 > PageTotal)
                {
                    break;
                }
                num++;
            }

            //循环遍历移除控件
            foreach (Control c in _listControl)
            {
                this.Controls.Remove(c);
            }
            _listControl = new List<Control>();
            ButtonW button = null;
            //循环创建控件
            if (IsShowGroup)
            {

                for (int i = GroupSize * (CurrentGroup - 1); i < GroupSize * CurrentGroup; i++)
                {
                    if (i + 1 > PageTotal || i + 1 <= 0)
                    {
                        break;
                    }

                    button = new ButtonW();
                    button.Style = Style;

                    button.Text = Convert.ToString(i + 1);
                    button.Width = ButtonWidth;
                    button.Height = ButtonHeight;
                    //button.Location = new Point(250 + x, y);//btnPreGroup.Location
                    button.Location = new Point(btnPreGroup.Location.X - x - ButtonDistance - 25,
                                                btnPreGroup.Location.Y); //btnPreGroup.Location
                    ButtonDistance = 2;
                    button.Anchor =
                        AnchorStyles.Top | AnchorStyles.Right;
                    button.Click += new EventHandler(OnClick);
                    this.Controls.Add(button);
                    button.BringToFront();
                    _listControl.Add(button); //添加进分页按钮的集合
                    x += ButtonWidth + ButtonDistance;
                }
                if (!IsShowGroup)
                {
                    btnPreGroup.Visible = false;
                    btnNextGroup.Visible = false;
                }
                else
                {
                    btnPreGroup.Visible = true;
                    btnNextGroup.Visible = true;
                    //上一组是否可用
                    if (CurrentGroup == 1)
                    {
                        btnPreGroup.Enabled = false;
                    }
                    else
                    {
                        btnPreGroup.Enabled = true;
                    }
                    //下一组是否可用
                    if (CurrentGroup == GroupTotal)
                    {
                        btnNextGroup.Enabled = false;
                    }
                    else
                    {
                        btnNextGroup.Enabled = true;
                    }
                }

            }

        }
Пример #2
0
        /// <summary>
        /// 创建分页数字按钮
        /// </summary>
        private void BuildPageControl()
        {
            int x   = 0; //按钮横坐标
            int num = 0; //按钮数

            for (int i = GroupSize * (CurrentGroup - 1); i < GroupSize * CurrentGroup; i++)
            {
                if (i + 1 > PageTotal)
                {
                    break;
                }
                num++;
            }

            //循环遍历移除控件
            foreach (Control c in _listControl)
            {
                this.Controls.Remove(c);
            }
            _listControl = new List <Control>();
            ButtonW button = null;

            //循环创建控件
            if (IsShowGroup)
            {
                for (int i = GroupSize * (CurrentGroup - 1); i < GroupSize * CurrentGroup; i++)
                {
                    if (i + 1 > PageTotal || i + 1 <= 0)
                    {
                        break;
                    }

                    button       = new ButtonW();
                    button.Style = Style;

                    button.Text   = Convert.ToString(i + 1);
                    button.Width  = ButtonWidth;
                    button.Height = ButtonHeight;
                    //button.Location = new Point(250 + x, y);//btnPreGroup.Location
                    button.Location = new Point(btnPreGroup.Location.X - x - ButtonDistance - 25,
                                                btnPreGroup.Location.Y); //btnPreGroup.Location
                    ButtonDistance = 2;
                    button.Anchor  =
                        AnchorStyles.Top | AnchorStyles.Right;
                    button.Click += new EventHandler(OnClick);
                    this.Controls.Add(button);
                    button.BringToFront();
                    _listControl.Add(button); //添加进分页按钮的集合
                    x += ButtonWidth + ButtonDistance;
                }
                if (!IsShowGroup)
                {
                    btnPreGroup.Visible  = false;
                    btnNextGroup.Visible = false;
                }
                else
                {
                    btnPreGroup.Visible  = true;
                    btnNextGroup.Visible = true;
                    //上一组是否可用
                    if (CurrentGroup == 1)
                    {
                        btnPreGroup.Enabled = false;
                    }
                    else
                    {
                        btnPreGroup.Enabled = true;
                    }
                    //下一组是否可用
                    if (CurrentGroup == GroupTotal)
                    {
                        btnNextGroup.Enabled = false;
                    }
                    else
                    {
                        btnNextGroup.Enabled = true;
                    }
                }
            }
        }