C# Winform实现自定义分页控件

  public Action GetPageData { get; set; }

  private Color _FontColor;

  [Browsable(true), Description("设置字体颜色")]

  public Color FontColor

  {

  get => _FontColor; set

  {

  lb_down.ForeColor = lb_end.ForeColor = lb_go.ForeColor = lb_home.ForeColor = lb_page.ForeColor = lb_up.ForeColor = value;

  }

  }

  private int _DataCount;

  [Description("数据总数量")]

  public int DataCount

  {

  get => _DataCount;

  set

  {

  _DataCount = value;

  lb_page.Text = PageIndex + "/" + PageTotal;

  }

  }

  private int _PageSize;

  [Description("页显示数量")]

  public int PageSize

  {

  get

  {

  return _PageSize <= 0 ? 50 : _PageSize;

  }

  set

  {

  _PageSize = value;

  lb_page.Text = PageIndex + "/" + PageTotal;

  }

  }

  private int _PageTotal;

  [Description("总页数")]

  public int PageTotal

  {

  get

  {

  if (DataCount % PageSize == 0)

  {

  _PageTotal = DataCount / PageSize;

  }

  else

  {

  _PageTotal = DataCount / PageSize + 1;

  }

  return _PageTotal <= 0 ? 1 : _PageTotal;

  }

  }

  ​​​​​​​ private int _PageIndex;

  [Description("当前页数")]

  public int PageIndex

  {

  get

  {

  return _PageIndex <= 0 ? 1 : _PageIndex;

  }

  private set

  {

  _PageIndex = value;

  if (_PageIndex <= 0)

  {

  _PageIndex = 1;

  }

  if (_PageIndex > PageTotal)

  {

  _PageIndex = PageTotal;

  }

  if (GetPageData != null)

  {

  GetPageData(_PageIndex);

  lb_page.Text = _PageIndex + "/" + PageTotal;

  }

  }

  }