page

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

using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace PagerForWinForm
{
    [DefaultEvent("PageIndexChanged"), DefaultProperty("RecordCount"), Description("WinForm下的分页控件"), ToolboxBitmap(typeof(WinFormPager), "Resources.Bitmap.pager")]
    public partial class WinFormPager : UserControl
    {
        #region Members
        private string _BtnTextFirst = "首页";
        private string _BtnTextLast = "末页";
        private string _BtnTextNext = "下页";
        private string _BtnTextPrevious = "上页";
        private DisplayStyleEnum _DisplayStyle = DisplayStyleEnum.图片;
        private string _JumpText = "跳转";
        private int _PageCount;
        private int _PageIndex = 1;
        private int _PageSize = 10;
        private int _RecordCount;
        private TextImageRalitionEnum _TextImageRalition = TextImageRalitionEnum.图片显示在文字前方;
        private string PagerText = "总共{0}条记录,当前第{1}页,共{2}页,每页{3}条记录";

public enum DisplayStyleEnum
        {
            图片 = 1,
            图片及文字 = 3,
            文字 = 2
        }

public delegate void EventHandler(object sender, EventArgs e);

public enum TextImageRalitionEnum
        {
            图片显示在文字后方 = 4,
            图片显示在文字前方 = 3,
            图片显示在文字上方 = 1,
            图片显示在文字下方 = 2
        }

[Description("更改页面索引事件"), Category("自定义事件")]
        public event EventHandler PageIndexChanged;

[Category("自定义属性"), DefaultValue("首页"), Description("首页按钮文字,当DisplayStyle=文字或DisplayStyle=图片及文字时生效")]
        public string BtnTextFirst
        {
            get
            {
                return this._BtnTextFirst;
            }
            set
            {
                this._BtnTextFirst = value;
                this.SetDisplayStyle();
            }
        }

[Description("末页按钮文字,当DisplayStyle=文字或DisplayStyle=图片及文字时生效"), DefaultValue("末页"), Category("自定义属性")]
        public string BtnTextLast
        {
            get
            {
                return this._BtnTextLast;
            }
            set
            {
                this._BtnTextLast = value;
                this.SetDisplayStyle();
            }
        }

[DefaultValue("下一页"), Category("自定义属性"), Description("下一页按钮文字,当DisplayStyle=文字或DisplayStyle=图片及文字时生效")]
        public string BtnTextNext
        {
            get
            {
                return this._BtnTextNext;
            }
            set
            {
                this._BtnTextNext = value;
                this.SetDisplayStyle();
            }
        }

[DefaultValue("上一页"), Description("上一页按钮文字,当DisplayStyle=文字或DisplayStyle=图片及文字时生效"), Category("自定义属性")]
        public string BtnTextPrevious
        {
            get
            {
                return this._BtnTextPrevious;
            }
            set
            {
                this._BtnTextPrevious = value;
                this.SetDisplayStyle();
            }
        }

[Category("自定义属性"), DefaultValue(1), Description("显示类型:图片、文字、图片及文字")]
        public DisplayStyleEnum DisplayStyle
        {
            get
            {
                return this._DisplayStyle;
            }
            set
            {
                this._DisplayStyle = value;
                this.SetDisplayStyle();
            }
        }

[Description("跳转按钮文字"), Category("自定义属性"), DefaultValue("跳转")]
        public string JumpText
        {
            get
            {
                return this._JumpText;
            }
            set
            {
                this._JumpText = value;
                this.btnToPageIndex.Text = this._JumpText;
            }
        }

private int PageCount
        {
            get
            {
                return this._PageCount;
            }
        }

[DefaultValue(1), Category("自定义属性"), Description("当前显示的页数")]
        public int PageIndex
        {
            get
            {
                return this._PageIndex;
            }
            set
            {
                this._PageIndex = value;
            }
        }

[DefaultValue(10), Description("每页显示的记录数"), Category("自定义属性")]
        public int PageSize
        {
            get
            {
                return this._PageSize;
            }
            set
            {
                if (value <= 1)
                {
                    value = 10;
                }
                this._PageSize = value;
                this.SetLabelLocation();
            }
        }

[Description("要分页的总记录数"), Category("自定义属性")]
        public int RecordCount
        {
            get
            {
                return this._RecordCount;
            }
            set
            {
                this._RecordCount = value;
            }
        }

[DefaultValue(3), Description("图片和文字显示相对位置,当DisplayStyle=文字或DisplayStyle=图片及文字时生效"), Category("自定义属性")]
        public TextImageRalitionEnum TextImageRalitions
        {
            get
            {
                return this._TextImageRalition;
            }
            set
            {
                this._TextImageRalition = value;
                this.SetDisplayStyle();
            }
        }

#endregion
        public WinFormPager()
        {
            InitializeComponent();
        }

#region Methods

protected int GetPageCount(int RecordCounts, int PageSizes)
        {
            int num = 0;
            string str = (Convert.ToDouble(RecordCounts) / Convert.ToDouble(PageSizes)).ToString();
            if (str.IndexOf(".") < 0)
            {
                return Convert.ToInt32(str);
            }
            string[] strArray = Regex.Split(str, @"\.", RegexOptions.IgnoreCase);
            if (!string.IsNullOrEmpty(strArray[1].ToString()))
            {
                num = Convert.ToInt32(strArray[0]) + 1;
            }
            return num;
        }

protected void SetBtnEnabled()
        {
            if (this._PageIndex == 1)
            {
                this.btnFirst.Enabled = false;
                this.btnPrevious.Enabled = false;
                this.btnNext.Enabled =  true;
                this.btnLast.Enabled = true;
                //this.btnNext.Enabled = (this._PageCount <= 1) ? false : true;
                //this.btnLast.Enabled = (this._PageCount <= 1) ? false : true;
            }
            else if ((this._PageIndex > 1) && (this._PageIndex < this._PageCount))
            {
                this.btnFirst.Enabled = true;
                this.btnPrevious.Enabled = true;
                this.btnNext.Enabled = true;
                this.btnLast.Enabled = true;
            }
            else if (this._PageIndex == this._PageCount)
            {
                this.btnFirst.Enabled = true;
                this.btnPrevious.Enabled = true;
                this.btnNext.Enabled = false;
                this.btnLast.Enabled = false;
            }
        }

private void SetDisplayStyle()
        {
            TextImageRelation imageBeforeText = TextImageRelation.ImageBeforeText;
            if (this.TextImageRalitions == TextImageRalitionEnum.图片显示在文字上方)
            {
                imageBeforeText = TextImageRelation.ImageAboveText;
            }
            else if (this.TextImageRalitions == TextImageRalitionEnum.图片显示在文字下方)
            {
                imageBeforeText = TextImageRelation.TextAboveImage;
            }
            else if (this.TextImageRalitions == TextImageRalitionEnum.图片显示在文字前方)
            {
                imageBeforeText = TextImageRelation.ImageBeforeText;
            }
            else if (this.TextImageRalitions == TextImageRalitionEnum.图片显示在文字后方)
            {
                imageBeforeText = TextImageRelation.TextBeforeImage;
            }
            if (this.DisplayStyle == DisplayStyleEnum.图片)
            {
                this.btnFirst.ImageList = this.btnPrevious.ImageList = this.btnNext.ImageList = this.btnLast.ImageList = this.imglstPager;
                this.btnFirst.ImageIndex = 0;
                this.btnPrevious.ImageIndex = 1;
                this.btnNext.ImageIndex = 2;
                this.btnLast.ImageIndex = 3;
                this.btnFirst.Text = this.btnPrevious.Text = this.btnNext.Text = this.btnLast.Text = "";
                this.btnFirst.TextImageRelation = this.btnPrevious.TextImageRelation = this.btnNext.TextImageRelation = this.btnLast.TextImageRelation = TextImageRelation.Overlay;
            }
            else if (this.DisplayStyle == DisplayStyleEnum.文字)
            {
                this.btnFirst.ImageList = this.btnPrevious.ImageList = this.btnNext.ImageList = (ImageList)(this.btnLast.ImageList = null);
                this.btnFirst.Text = string.IsNullOrEmpty(this.BtnTextFirst) ? "首页" : this.BtnTextFirst;
                this.btnPrevious.Text = string.IsNullOrEmpty(this.BtnTextPrevious) ? "上页" : this.BtnTextPrevious;
                this.btnNext.Text = string.IsNullOrEmpty(this.BtnTextNext) ? "下页" : this.BtnTextNext;
                this.btnLast.Text = string.IsNullOrEmpty(this.BtnTextLast) ? "末页" : this.BtnTextLast;
                this.btnFirst.TextImageRelation = this.btnPrevious.TextImageRelation = this.btnNext.TextImageRelation = this.btnLast.TextImageRelation = TextImageRelation.Overlay;
            }
            else if (this.DisplayStyle == DisplayStyleEnum.图片及文字)
            {
                this.btnFirst.ImageList = this.btnPrevious.ImageList = this.btnNext.ImageList = this.btnLast.ImageList = this.imglstPager;
                this.btnFirst.ImageIndex = 0;
                this.btnPrevious.ImageIndex = 1;
                this.btnNext.ImageIndex = 2;
                this.btnLast.ImageIndex = 3;
                this.btnFirst.Text = string.IsNullOrEmpty(this.BtnTextFirst) ? "首页" : this.BtnTextFirst;
                this.btnPrevious.Text = string.IsNullOrEmpty(this.BtnTextPrevious) ? "上页" : this.BtnTextPrevious;
                this.btnNext.Text = string.IsNullOrEmpty(this.BtnTextNext) ? "下页" : this.BtnTextNext;
                this.btnLast.Text = string.IsNullOrEmpty(this.BtnTextLast) ? "末页" : this.BtnTextLast;
                this.btnFirst.TextImageRelation = this.btnPrevious.TextImageRelation = this.btnNext.TextImageRelation = this.btnLast.TextImageRelation = imageBeforeText;
            }
        }

protected void SetLabelLocation()
        {
            this.btnFirst.Left = (this.lblPager.Left + this.lblPager.Width) + 10;
            this.btnPrevious.Left = this.btnFirst.Left + this.btnFirst.Width;
            this.btnNext.Left = this.btnPrevious.Left + this.btnPrevious.Width;
            this.btnLast.Left = this.btnNext.Left + this.btnNext.Width;
            this.lbPre.Left = (this.btnLast.Left + this.btnLast.Width) + 10;
            this.txtToPageIndex.Left = this.lbPre.Left + this.lbPre.Width;
            this.lbEnd.Left = this.txtToPageIndex.Left + this.txtToPageIndex.Width;
            this.btnToPageIndex.Left = this.lbEnd.Left + this.lbEnd.Width;
        }

private void SetPagerText()
        {
            string[] strArray = new string[] { this.RecordCount.ToString(), this.PageIndex.ToString(), this.PageCount.ToString(), this.PageSize.ToString() };
            this.lblPager.Text = string.Format(this.PagerText, (object[])strArray);
        }

#endregion

#region Events

private void CustomEvent(object sender, EventArgs e)
        {
            try
            {
                this.PageIndexChanged(sender, e);
            }
            catch (Exception)
            {
                MessageBox.Show("未找到PageIndexChanged事件!");
            }
        }

private void btnFirst_Click(object sender, EventArgs e)
        {
            this._PageIndex = 1;
            this.SetPagerText();
            this.SetBtnEnabled();
            this.SetLabelLocation();
            this.CustomEvent(sender, e);
        }

private void btnLast_Click(object sender, EventArgs e)
        {
            this._PageIndex = this._PageCount;
            this.SetPagerText();
            this.SetBtnEnabled();
            this.SetLabelLocation();
            this.CustomEvent(sender, e);
        }

private void btnNext_Click(object sender, EventArgs e)
        {
            int num = this._PageIndex;
            try
            {
                int num2 = Convert.ToInt32(num) + 1;
                if (num2 >= this._RecordCount)
                {
                    num2 = this._RecordCount;
                }
                this._PageIndex = num2;
                this.SetPagerText();
                this.SetBtnEnabled();
                this.SetLabelLocation();
                this.CustomEvent(sender, e);
            }
            catch (Exception)
            {
            }
        }

private void btnPrevious_Click(object sender, EventArgs e)
        {
            int num = this._PageIndex;
            try
            {
                int num2 = Convert.ToInt32(num) - 1;
                if (num2 <= 0)
                {
                    num2 = 1;
                }
                this._PageIndex = num2;
                this.SetPagerText();
                this.SetBtnEnabled();
                this.SetLabelLocation();
                this.CustomEvent(sender, e);
            }
            catch (Exception)
            {
            }
        }

private void btnToPageIndex_Click(object sender, EventArgs e)
        {
            string text = this.txtToPageIndex.Text;
            int num = this._PageIndex;
            if (string.IsNullOrEmpty(text))
            {
                num = 1;
                this.txtToPageIndex.Text = "1";
            }
            else
            {
                num = Convert.ToInt32(text);
                if (num > this._PageCount)
                {
                    num = this._PageCount;
                    this.txtToPageIndex.Text = this._PageCount.ToString();
                }
                else
                {
                    this._PageIndex = num;
                    this.SetPagerText();
                    this.SetBtnEnabled();
                    this.SetLabelLocation();
                    this.CustomEvent(sender, e);
                }
            }
        }

private void WinFormPager_Load(object sender, EventArgs e)
        {
            this.SetBtnEnabled();
            this.btnToPageIndex.Text = this._JumpText;
        }

private void WinFormPager_Paint(object sender, PaintEventArgs e)
        {
            this._PageCount = this.GetPageCount(this._RecordCount, this._PageSize);
            this.SetPagerText();
            this.SetDisplayStyle();
            this.SetLabelLocation();

}

private void WinFormPager_MouseMove(object sender, MouseEventArgs e)
        {
            foreach (Control control in base.Controls)
            {
                if (control is Button)
                {
                    Button button = (Button)control;
                    button.BackColor = Color.Transparent;
                    button.FlatAppearance.BorderColor = Color.White;
                    button.FlatAppearance.MouseDownBackColor = Color.Transparent;
                    button.FlatAppearance.MouseOverBackColor = Color.Transparent;
                }
            }
        }

#endregion

#region AutoGeneratee

#endregion

}
}

时间: 2024-10-15 11:13:18

page的相关文章

让被巡视对象摸不着规律

http://v.qq.com/page/l/o/t/x0414yqyi7y.htmlhttp://v.qq.com/page/4/z/l/t0414qgn8mp.htmlhttp://v.qq.com/page/p/c/r/j0414oxk8t7.htmlhttp://v.qq.com/page/l/5/1/f0414554cxg.htmlhttp://v.qq.com/page/f/f/o/w04144bi3ve.htmlhttp://v.qq.com/page/j/n/u/j04148kz

微信小程序 app注册小程序+page注册页面代码一

注册小程序代码:app.js //app.js App({ onLaunch: function(){ var log = wx.getStorageSync("logs") || [] log.unshift(Date.now()) wx.setStorageSync("logs", log) wx.login({ success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId } })

SpringBoot接口服务处理Whitelabel Error Page

转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50915979 <SpringBoot接口服务处理Whitelabel Error Page> <Maven依赖载入错误的情况分析> <Java Webproject转换为基于Maven的Webproject> <Maven Webproject执行异常:Maven.multiModuleProjectDirectory system propery

page request session application 范围

在JSP页面中的对象,包括用户创建的对象(例如,JavaBean对象)和JSP的隐含对象,都有一个范围属性.范围定义了在什么时间内, 在哪一个JSP页面中可以访问这些对象.例如,session对象在会话期间内,可以在多个页面中被访问.application对象在整个Web应 用程序的生命周期中都可以被访问.在JSP中,有4种范围,如下所示. 1. page范围 具有page范围的对象被绑定到javax.servlet.jsp.PageContext对象中.在这个范围内的对象,只能在创建对象的页面

使用Page Speed Online改善网站速度

Google是一个伟大的企业,一直以来都非常重视网站的用户体验:对于用户体验,笔者认为,一个网站的用户体验好不好,一个很重要的因素就是网站的打开速度(加载速度):Google最近发布的在线网页加速工具--Page Speed Online,可分析任何网站的速度并且提供如何改进的建议. Page Speed对于一个网站来说,是一个很不错的工具,因为相当一部分的江西seo站长并不了解影响自己网站加载速度的因素有哪些,也就不知道如何去改进自己网站的加载速度.下面就以笔者的博客为例,来阐述一下Page

JSP(Java Server Page)九大内置对象

× Web程序的请求相应模式(请求[request].响应[response]) × form method="get"和method="post"提交方式的区别                  1.get:以明文形式通过url进行参数的传递,数据能在url获取,提交的数据最多不超过2KB,安全性低但效率比post高.                 适用于提交数据量不大,安全性不高的数据.eg:搜索.查询等               2.post:将用户提交的

4.Jsp的page指令

<%@ page 属性="属性值"....%>          常见属性:             language="java"             import=导入需要的jar包             contentType="text/html;charset=utf-8"

[Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js

You often use the same data in different ways across pages. This lesson walks you through setting up multiple pages, retrieving the same data, then displaying it for each page's use-case. index.vue: <template> <div> <form @submit.prevent=&q

PHP---分页类(page.class.php)

1 <?php 2 class Page 3 { 4 private $total; //数据总记录数 5 private $listRows; //每页显示的行数 6 private $limit; //偏移量长度 7 private $url; 8 private $pageNum; //总页数 9 private $config=array('header'=>'个记录','prev'=>'上一页','next'=>'下一页','first'=>'首页','last'=

使用Github Page鼓励自己每日编程

动机 三天不练手生,编程的基础训练本身是很枯燥的,需要很多的认真与坚持.无论是Debug的经验,语法规则的记忆,还是各类基础的算法运用,都需要持之以恒的认真.Github的"打卡"以及展示页,可以作为一个小小的奖励,鼓励自己每日坚持. 方案 因为github是支持jekyll引擎的,所以使用jekyll生成项目是足够好的选择,还有新一点的工具Hexo,都能快速地在Github Pages上面搭建blog.难度上会比WordPress大一点点,但是足够geek啊.花了一个下午折腾,终于搭