(十二)c#Winform自定义控件-分页控件
程序员文章站
2022-05-29 10:26:24
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control 如果觉得写的还行,请点个 star 支持一下吧 欢迎前来交流探讨: 企鹅群568015492 目录 ......
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
开源地址:
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492
目录
准备工作
当一个列表加载数据过多时,比如datagridview,如果数据过多,则可能超出内存,相应慢等问题,此时需要用到翻页控件。
设计思路,对翻页控件定义接口,基类实现,如果所列的翻页控件样式或功能无法满足你的需求的话,你只需要基类翻页控件基类或者实现接口即可。
定义接口是因为后面的一些列表控件内置了翻页控件,为了达到兼容扩展,所有使用了接口定义约束。
开始
首先需要一个分页事件用到的委托,偷懒,只写了一个
[serializable] [comvisible(true)] public delegate void pagecontroleventhandler(object currentsource);
我们先定义一个接口ipagecontrol
1 public interface ipagecontrol 2 { 3 /// <summary> 4 /// 数据源改变时发生 5 /// </summary> 6 event pagecontroleventhandler showsourcechanged; 7 /// <summary> 8 /// 数据源 9 /// </summary> 10 list<object> datasource { get; set; } 11 /// <summary> 12 /// 显示数量 13 /// </summary> 14 int pagesize { get; set; } 15 /// <summary> 16 /// 开始下标 17 /// </summary> 18 int startindex { get; set; } 19 /// <summary> 20 /// 第一页 21 /// </summary> 22 void firstpage(); 23 /// <summary> 24 /// 前一页 25 /// </summary> 26 void previouspage(); 27 /// <summary> 28 /// 下一页 29 /// </summary> 30 void nextpage(); 31 /// <summary> 32 /// 最后一页 33 /// </summary> 34 void endpage(); 35 /// <summary> 36 /// 重新加载 37 /// </summary> 38 void reload(); 39 /// <summary> 40 /// 获取当前页数据 41 /// </summary> 42 /// <returns></returns> 43 list<object> getcurrentsource(); 44 /// <summary> 45 /// 总页数 46 /// </summary> 47 int pagecount { get; set; } 48 /// <summary> 49 /// 当前页 50 /// </summary> 51 int pageindex { get; set; } 52 }
然后定义一个分页基类控件,添加一个用户控件,命名ucpagercontrolbase,并实现接口ipagecontrol
看下属性
1 /// <summary> 2 /// 总页数 3 /// </summary> 4 public virtual int pagecount 5 { 6 get; 7 set; 8 } 9 private int m_pageindex = 1; 10 /// <summary> 11 /// 当前页码 12 /// </summary> 13 public virtual int pageindex 14 { 15 get { return m_pageindex; } 16 set { m_pageindex = value; } 17 } 18 /// <summary> 19 /// 关联的数据源 20 /// </summary> 21 public virtual list<object> datasource { get; set; } 22 public virtual event pagecontroleventhandler showsourcechanged; 23 private int m_pagesize = 1; 24 /// <summary> 25 /// 每页显示数量 26 /// </summary> 27 [description("每页显示数量"), category("自定义")] 28 public virtual int pagesize 29 { 30 get { return m_pagesize; } 31 set { m_pagesize = value; } 32 } 33 private int startindex = 0; 34 /// <summary> 35 /// 开始的下标 36 /// </summary> 37 [description("开始的下标"), category("自定义")] 38 public virtual int startindex 39 { 40 get { return startindex; } 41 set 42 { 43 startindex = value; 44 if (startindex <= 0) 45 startindex = 0; 46 } 47 }
然后定义虚函数,并做一些默认实现
/// <summary> /// 第一页 /// </summary> public virtual void firstpage() { if (datasource == null) return; startindex = 0; var s = getcurrentsource(); if (showsourcechanged != null) { showsourcechanged(s); } } /// <summary> /// 上一页 /// </summary> public virtual void previouspage() { if (datasource == null) return; if (startindex == 0) return; startindex -= m_pagesize; if (startindex < 0) startindex = 0; var s = getcurrentsource(); if (showsourcechanged != null) { showsourcechanged(s); } } /// <summary> /// 下一页 /// </summary> public virtual void nextpage() { if (datasource == null) return; if (startindex + m_pagesize >= datasource.count) { return; } startindex += m_pagesize; if (startindex < 0) startindex = 0; var s = getcurrentsource(); if (showsourcechanged != null) { showsourcechanged(s); } } /// <summary> /// 最后一页 /// </summary> public virtual void endpage() { if (datasource == null) return; startindex = datasource.count - m_pagesize; if (startindex < 0) startindex = 0; var s = getcurrentsource(); if (showsourcechanged != null) { showsourcechanged(s); } } /// <summary> /// 刷新数据 /// </summary> public virtual void reload() { var s = getcurrentsource(); if (showsourcechanged != null) { showsourcechanged(s); } } /// <summary> /// 获取当前页数据 /// </summary> /// <returns></returns> public virtual list<object> getcurrentsource() { if (datasource == null) return null; int intshowcount = m_pagesize; if (intshowcount + startindex > datasource.count) intshowcount = datasource.count - startindex; object[] objs = new object[intshowcount]; datasource.copyto(startindex, objs, 0, intshowcount); var lst = objs.tolist(); bool blnleft = false; bool blnright = false; if (lst.count > 0) { if (datasource.indexof(lst[0]) > 0) { blnleft = true; } else { blnleft = false; } if (datasource.indexof(lst[lst.count - 1]) >= datasource.count - 1) { blnright = false; } else { blnright = true; } } showbtn(blnleft, blnright); return lst; } /// <summary> /// 控制按钮显示 /// </summary> /// <param name="blnleftbtn">是否显示上一页,第一页</param> /// <param name="blnrightbtn">是否显示下一页,最后一页</param> protected virtual void showbtn(bool blnleftbtn, bool blnrightbtn) { }
如此基类就完成了,看下完整代码
1 // 版权所有 黄正辉 交流群:568015492 qq:623128629 2 // 文件名称:ucpagercontrolbase.cs 3 // 创建日期:2019-08-15 16:00:41 4 // 功能描述:pagecontrol 5 // 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control 6 using system; 7 using system.collections.generic; 8 using system.componentmodel; 9 using system.drawing; 10 using system.data; 11 using system.linq; 12 using system.text; 13 using system.windows.forms; 14 15 namespace hzh_controls.controls 16 { 17 [toolboxitem(false)] 18 public class ucpagercontrolbase : usercontrol, ipagecontrol 19 { 20 #region 构造 21 /// <summary> 22 /// 必需的设计器变量。 23 /// </summary> 24 private system.componentmodel.icontainer components = null; 25 26 /// <summary> 27 /// 清理所有正在使用的资源。 28 /// </summary> 29 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 30 protected override void dispose(bool disposing) 31 { 32 if (disposing && (components != null)) 33 { 34 components.dispose(); 35 } 36 base.dispose(disposing); 37 } 38 39 #region 组件设计器生成的代码 40 41 /// <summary> 42 /// 设计器支持所需的方法 - 不要 43 /// 使用代码编辑器修改此方法的内容。 44 /// </summary> 45 private void initializecomponent() 46 { 47 this.suspendlayout(); 48 // 49 // ucpagercontrolbase 50 // 51 this.autoscalemode = system.windows.forms.autoscalemode.none; 52 this.name = "ucpagercontrolbase"; 53 this.size = new system.drawing.size(304, 58); 54 this.load += new system.eventhandler(this.ucpagercontrolbase_load); 55 this.resumelayout(false); 56 57 } 58 59 #endregion 60 #endregion 61 /// <summary> 62 /// 总页数 63 /// </summary> 64 public virtual int pagecount 65 { 66 get; 67 set; 68 } 69 private int m_pageindex = 1; 70 /// <summary> 71 /// 当前页码 72 /// </summary> 73 public virtual int pageindex 74 { 75 get { return m_pageindex; } 76 set { m_pageindex = value; } 77 } 78 /// <summary> 79 /// 关联的数据源 80 /// </summary> 81 public virtual list<object> datasource { get; set; } 82 public virtual event pagecontroleventhandler showsourcechanged; 83 private int m_pagesize = 1; 84 /// <summary> 85 /// 每页显示数量 86 /// </summary> 87 [description("每页显示数量"), category("自定义")] 88 public virtual int pagesize 89 { 90 get { return m_pagesize; } 91 set { m_pagesize = value; } 92 } 93 private int startindex = 0; 94 /// <summary> 95 /// 开始的下标 96 /// </summary> 97 [description("开始的下标"), category("自定义")] 98 public virtual int startindex 99 { 100 get { return startindex; } 101 set 102 { 103 startindex = value; 104 if (startindex <= 0) 105 startindex = 0; 106 } 107 } 108 109 public ucpagercontrolbase() 110 { 111 initializecomponent(); 112 } 113 114 private void ucpagercontrolbase_load(object sender, eventargs e) 115 { 116 if (datasource == null) 117 showbtn(false, false); 118 else 119 { 120 showbtn(false, datasource.count > pagesize); 121 } 122 } 123 /// <summary> 124 /// 第一页 125 /// </summary> 126 public virtual void firstpage() 127 { 128 if (datasource == null) 129 return; 130 startindex = 0; 131 var s = getcurrentsource(); 132 133 if (showsourcechanged != null) 134 { 135 showsourcechanged(s); 136 } 137 } 138 /// <summary> 139 /// 上一页 140 /// </summary> 141 public virtual void previouspage() 142 { 143 if (datasource == null) 144 return; 145 if (startindex == 0) 146 return; 147 startindex -= m_pagesize; 148 if (startindex < 0) 149 startindex = 0; 150 var s = getcurrentsource(); 151 152 if (showsourcechanged != null) 153 { 154 showsourcechanged(s); 155 } 156 } 157 /// <summary> 158 /// 下一页 159 /// </summary> 160 public virtual void nextpage() 161 { 162 if (datasource == null) 163 return; 164 if (startindex + m_pagesize >= datasource.count) 165 { 166 return; 167 } 168 startindex += m_pagesize; 169 if (startindex < 0) 170 startindex = 0; 171 var s = getcurrentsource(); 172 173 if (showsourcechanged != null) 174 { 175 showsourcechanged(s); 176 } 177 } 178 /// <summary> 179 /// 最后一页 180 /// </summary> 181 public virtual void endpage() 182 { 183 if (datasource == null) 184 return; 185 startindex = datasource.count - m_pagesize; 186 if (startindex < 0) 187 startindex = 0; 188 var s = getcurrentsource(); 189 190 if (showsourcechanged != null) 191 { 192 showsourcechanged(s); 193 } 194 } 195 /// <summary> 196 /// 刷新数据 197 /// </summary> 198 public virtual void reload() 199 { 200 var s = getcurrentsource(); 201 if (showsourcechanged != null) 202 { 203 showsourcechanged(s); 204 } 205 } 206 /// <summary> 207 /// 获取当前页数据 208 /// </summary> 209 /// <returns></returns> 210 public virtual list<object> getcurrentsource() 211 { 212 if (datasource == null) 213 return null; 214 int intshowcount = m_pagesize; 215 if (intshowcount + startindex > datasource.count) 216 intshowcount = datasource.count - startindex; 217 object[] objs = new object[intshowcount]; 218 datasource.copyto(startindex, objs, 0, intshowcount); 219 var lst = objs.tolist(); 220 221 bool blnleft = false; 222 bool blnright = false; 223 if (lst.count > 0) 224 { 225 if (datasource.indexof(lst[0]) > 0) 226 { 227 blnleft = true; 228 } 229 else 230 { 231 blnleft = false; 232 } 233 if (datasource.indexof(lst[lst.count - 1]) >= datasource.count - 1) 234 { 235 blnright = false; 236 } 237 else 238 { 239 blnright = true; 240 } 241 } 242 showbtn(blnleft, blnright); 243 return lst; 244 } 245 246 /// <summary> 247 /// 控制按钮显示 248 /// </summary> 249 /// <param name="blnleftbtn">是否显示上一页,第一页</param> 250 /// <param name="blnrightbtn">是否显示下一页,最后一页</param> 251 protected virtual void showbtn(bool blnleftbtn, bool blnrightbtn) 252 { } 253 } 254 }
接下来就是具体的实现分页控件了,我们将实现2种不同样式的分页控件以适应不通的场景,
第一种
添加用户控件ucpagercontrol,继承ucpagercontrolbase
重新基类的部分函数
1 private void panel1_mousedown(object sender, mouseeventargs e) 2 { 3 previouspage(); 4 } 5 6 private void panel2_mousedown(object sender, mouseeventargs e) 7 { 8 nextpage(); 9 } 10 11 private void panel3_mousedown(object sender, mouseeventargs e) 12 { 13 firstpage(); 14 } 15 16 private void panel4_mousedown(object sender, mouseeventargs e) 17 { 18 endpage(); 19 } 20 21 protected override void showbtn(bool blnleftbtn, bool blnrightbtn) 22 { 23 panel1.visible = panel3.visible = blnleftbtn; 24 panel2.visible = panel4.visible = blnrightbtn; 25 }
完成,是不是很简单,看下全部代码
1 // 版权所有 黄正辉 交流群:568015492 qq:623128629 2 // 文件名称:ucpagercontrol.cs 3 // 创建日期:2019-08-15 16:00:32 4 // 功能描述:pagecontrol 5 // 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control 6 using system; 7 using system.collections.generic; 8 using system.componentmodel; 9 using system.drawing; 10 using system.data; 11 using system.linq; 12 using system.text; 13 using system.windows.forms; 14 15 namespace hzh_controls.controls 16 { 17 [toolboxitem(true)] 18 public partial class ucpagercontrol : ucpagercontrolbase 19 { 20 public ucpagercontrol() 21 { 22 initializecomponent(); 23 } 24 25 private void panel1_mousedown(object sender, mouseeventargs e) 26 { 27 previouspage(); 28 } 29 30 private void panel2_mousedown(object sender, mouseeventargs e) 31 { 32 nextpage(); 33 } 34 35 private void panel3_mousedown(object sender, mouseeventargs e) 36 { 37 firstpage(); 38 } 39 40 private void panel4_mousedown(object sender, mouseeventargs e) 41 { 42 endpage(); 43 } 44 45 protected override void showbtn(bool blnleftbtn, bool blnrightbtn) 46 { 47 panel1.visible = panel3.visible = blnleftbtn; 48 panel2.visible = panel4.visible = blnrightbtn; 49 } 50 } 51 }
1 namespace hzh_controls.controls 2 { 3 partial class ucpagercontrol 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private system.componentmodel.icontainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.dispose(); 19 } 20 base.dispose(disposing); 21 } 22 23 #region 组件设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void initializecomponent() 30 { 31 this.tablelayoutpanel1 = new system.windows.forms.tablelayoutpanel(); 32 this.panel4 = new system.windows.forms.panel(); 33 this.panel3 = new system.windows.forms.panel(); 34 this.panel2 = new system.windows.forms.panel(); 35 this.panel1 = new system.windows.forms.panel(); 36 this.tablelayoutpanel1.suspendlayout(); 37 this.suspendlayout(); 38 // 39 // tablelayoutpanel1 40 // 41 this.tablelayoutpanel1.columncount = 4; 42 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.percent, 25f)); 43 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.percent, 25f)); 44 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.percent, 25f)); 45 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.percent, 25f)); 46 this.tablelayoutpanel1.controls.add(this.panel4, 3, 0); 47 this.tablelayoutpanel1.controls.add(this.panel3, 0, 0); 48 this.tablelayoutpanel1.controls.add(this.panel2, 2, 0); 49 this.tablelayoutpanel1.controls.add(this.panel1, 1, 0); 50 this.tablelayoutpanel1.dock = system.windows.forms.dockstyle.fill; 51 this.tablelayoutpanel1.location = new system.drawing.point(0, 0); 52 this.tablelayoutpanel1.name = "tablelayoutpanel1"; 53 this.tablelayoutpanel1.padding = new system.windows.forms.padding(3); 54 this.tablelayoutpanel1.rowcount = 1; 55 this.tablelayoutpanel1.rowstyles.add(new system.windows.forms.rowstyle(system.windows.forms.sizetype.percent, 100f)); 56 this.tablelayoutpanel1.size = new system.drawing.size(304, 58); 57 this.tablelayoutpanel1.tabindex = 1; 58 // 59 // panel4 60 // 61 this.panel4.backgroundimage = global::hzh_controls.properties.resources.end; 62 this.panel4.backgroundimagelayout = system.windows.forms.imagelayout.zoom; 63 this.panel4.location = new system.drawing.point(228, 6); 64 this.panel4.name = "panel4"; 65 this.panel4.size = new system.drawing.size(68, 46); 66 this.panel4.tabindex = 3; 67 this.panel4.mousedown += new system.windows.forms.mouseeventhandler(this.panel4_mousedown); 68 // 69 // panel3 70 // 71 this.panel3.backgroundimage = global::hzh_controls.properties.resources.first; 72 this.panel3.backgroundimagelayout = system.windows.forms.imagelayout.zoom; 73 this.panel3.location = new system.drawing.point(6, 6); 74 this.panel3.name = "panel3"; 75 this.panel3.size = new system.drawing.size(68, 46); 76 this.panel3.tabindex = 2; 77 this.panel3.mousedown += new system.windows.forms.mouseeventhandler(this.panel3_mousedown); 78 // 79 // panel2 80 // 81 this.panel2.backgroundimage = global::hzh_controls.properties.resources.right; 82 this.panel2.backgroundimagelayout = system.windows.forms.imagelayout.zoom; 83 this.panel2.location = new system.drawing.point(154, 6); 84 this.panel2.name = "panel2"; 85 this.panel2.size = new system.drawing.size(68, 46); 86 this.panel2.tabindex = 1; 87 this.panel2.mousedown += new system.windows.forms.mouseeventhandler(this.panel2_mousedown); 88 // 89 // panel1 90 // 91 this.panel1.backgroundimage = global::hzh_controls.properties.resources.left; 92 this.panel1.backgroundimagelayout = system.windows.forms.imagelayout.zoom; 93 this.panel1.location = new system.drawing.point(80, 6); 94 this.panel1.name = "panel1"; 95 this.panel1.size = new system.drawing.size(68, 46); 96 this.panel1.tabindex = 0; 97 this.panel1.mousedown += new system.windows.forms.mouseeventhandler(this.panel1_mousedown); 98 // 99 // ucpagercontrol 100 // 101 this.autoscalemode = system.windows.forms.autoscalemode.none; 102 this.controls.add(this.tablelayoutpanel1); 103 this.name = "ucpagercontrol"; 104 this.tablelayoutpanel1.resumelayout(false); 105 this.resumelayout(false); 106 107 } 108 109 #endregion 110 111 private system.windows.forms.tablelayoutpanel tablelayoutpanel1; 112 private system.windows.forms.panel panel4; 113 private system.windows.forms.panel panel3; 114 private system.windows.forms.panel panel2; 115 private system.windows.forms.panel panel1; 116 } 117 }
第二种
这种和第一种的唯一区别就是页面计算生成的部分了
添加一个用户控件ucpagercontrol2,继承ucpagercontrolbase
属性如下
1 public override event pagecontroleventhandler showsourcechanged; 2 3 private list<object> m_datasource; 4 public override list<object> datasource 5 { 6 get 7 { 8 return m_datasource; 9 } 10 set 11 { 12 m_datasource = value; 13 if (m_datasource == null) 14 m_datasource = new list<object>(); 15 resetpagecount(); 16 } 17 } 18 private int m_intpagesize = 0; 19 public override int pagesize 20 { 21 get 22 { 23 return m_intpagesize; 24 } 25 set 26 { 27 m_intpagesize = value; 28 resetpagecount(); 29 } 30 }
其他更多的属性直接用基类的就可以
重写基类函数
1 public override void firstpage() 2 { 3 if (pageindex == 1) 4 return; 5 pageindex = 1; 6 startindex = (pageindex - 1) * pagesize; 7 reloadpage(); 8 var s = getcurrentsource(); 9 if (showsourcechanged != null) 10 { 11 showsourcechanged(s); 12 } 13 } 14 15 public override void previouspage() 16 { 17 if (pageindex <= 1) 18 { 19 return; 20 } 21 pageindex--; 22 23 startindex = (pageindex - 1) * pagesize; 24 reloadpage(); 25 var s = getcurrentsource(); 26 if (showsourcechanged != null) 27 { 28 showsourcechanged(s); 29 } 30 } 31 32 public override void nextpage() 33 { 34 if (pageindex >= pagecount) 35 { 36 return; 37 } 38 pageindex++; 39 startindex = (pageindex - 1) * pagesize; 40 reloadpage(); 41 var s = getcurrentsource(); 42 if (showsourcechanged != null) 43 { 44 showsourcechanged(s); 45 } 46 } 47 48 public override void endpage() 49 { 50 if (pageindex == pagecount) 51 return; 52 pageindex = pagecount; 53 startindex = (pageindex - 1) * pagesize; 54 reloadpage(); 55 var s = getcurrentsource(); 56 if (showsourcechanged != null) 57 { 58 showsourcechanged(s); 59 } 60 } 61 62 protected override void showbtn(bool blnleftbtn, bool blnrightbtn) 63 { 64 btnfirst.enabled = btnprevious.enabled = blnleftbtn; 65 btnnext.enabled = btnend.enabled = blnrightbtn; 66 }
一个重置总页数的函数
1 private void resetpagecount() 2 { 3 if (pagesize > 0) 4 { 5 pagecount = m_datasource.count / m_intpagesize + (m_datasource.count % m_intpagesize > 0 ? 1 : 0); 6 } 7 txtpage.maxvalue = pagecount; 8 txtpage.minvalue = 1; 9 reloadpage(); 10 }
一个重置计算当前页码列表的函数
private void reloadpage() { try { controlhelper.freezecontrol(tablelayoutpanel1, true); list<int> lst = new list<int>(); if (pagecount <= 9) { for (var i = 1; i <= pagecount; i++) { lst.add(i); } } else { if (this.pageindex <= 6) { for (var i = 1; i <= 7; i++) { lst.add(i); } lst.add(-1); lst.add(pagecount); } else if (this.pageindex > pagecount - 6) { lst.add(1); lst.add(-1); for (var i = pagecount - 6; i <= pagecount; i++) { lst.add(i); } } else { lst.add(1); lst.add(-1); var begin = pageindex - 2; var end = pageindex + 2; if (end > pagecount) { end = pagecount; begin = end - 4; if (pageindex - begin < 2) { begin = begin - 1; } } else if (end + 1 == pagecount) { end = pagecount; } for (var i = begin; i <= end; i++) { lst.add(i); } if (end != pagecount) { lst.add(-1); lst.add(pagecount); } } } for (int i = 0; i < 9; i++) { ucbtnext c = (ucbtnext)this.tablelayoutpanel1.controls.find("p" + (i + 1), false)[0]; if (i >= lst.count) { c.visible = false; } else { if (lst[i] == -1) { c.btntext = "..."; c.enabled = false; } else { c.btntext = lst[i].tostring(); c.enabled = true; } c.visible = true; if (lst[i] == pageindex) { c.rectcolor = color.fromargb(255, 77, 59); } else { c.rectcolor = color.fromargb(223, 223, 223); } } } showbtn(pageindex > 1, pageindex < pagecount); } finally { controlhelper.freezecontrol(tablelayoutpanel1, false); } }
跳转页面
1 private void page_btnclick(object sender, eventargs e) 2 { 3 pageindex = (sender as ucbtnext).btntext.toint(); 4 startindex = (pageindex - 1) * pagesize; 5 reloadpage(); 6 var s = getcurrentsource(); 7 8 if (showsourcechanged != null) 9 { 10 showsourcechanged(s); 11 } 12 } 13 private void btnfirst_btnclick(object sender, eventargs e) 14 { 15 firstpage(); 16 } 17 18 private void btnprevious_btnclick(object sender, eventargs e) 19 { 20 previouspage(); 21 } 22 23 private void btnnext_btnclick(object sender, eventargs e) 24 { 25 nextpage(); 26 } 27 28 private void btnend_btnclick(object sender, eventargs e) 29 { 30 endpage(); 31 } 32 33 private void btntopage_btnclick(object sender, eventargs e) 34 { 35 if (!string.isnullorempty(txtpage.inputtext)) 36 { 37 pageindex = txtpage.inputtext.toint(); 38 startindex = (pageindex - 1) * pagesize; 39 reloadpage(); 40 var s = getcurrentsource(); 41 if (showsourcechanged != null) 42 { 43 showsourcechanged(s); 44 } 45 } 46 }
至此完成所有逻辑,看下完整代码
1 // 版权所有 黄正辉 交流群:568015492 qq:623128629 2 // 文件名称:ucpagercontrol2.cs 3 // 创建日期:2019-08-15 16:00:37 4 // 功能描述:pagecontrol 5 // 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control 6 using system; 7 using system.collections.generic; 8 using system.componentmodel; 9 using system.drawing; 10 using system.data; 11 using system.linq; 12 using system.text; 13 using system.windows.forms; 14 15 namespace hzh_controls.controls.list 16 { 17 [toolboxitem(true)] 18 public partial class ucpagercontrol2 : ucpagercontrolbase 19 { 20 public ucpagercontrol2() 21 { 22 initializecomponent(); 23 txtpage.txtinput.keydown += txtinput_keydown; 24 } 25 26 void txtinput_keydown(object sender, keyeventargs e) 27 { 28 if (e.keycode == keys.enter) 29 { 30 btntopage_btnclick(null, null); 31 txtpage.inputtext = ""; 32 } 33 } 34 35 public override event pagecontroleventhandler showsourcechanged; 36 37 private list<object> m_datasource; 38 public override list<object> datasource 39 { 40 get 41 { 42 return m_datasource; 43 } 44 set 45 { 46 m_datasource = value; 47 if (m_datasource == null) 48 m_datasource = new list<object>(); 49 resetpagecount(); 50 } 51 } 52 private int m_intpagesize = 0; 53 public override int pagesize 54 { 55 get 56 { 57 return m_intpagesize; 58 } 59 set 60 { 61 m_intpagesize = value; 62 resetpagecount(); 63 } 64 } 65 66 public override void firstpage() 67 { 68 if (pageindex == 1) 69 return; 70 pageindex = 1; 71 startindex = (pageindex - 1) * pagesize; 72 reloadpage(); 73 var s = getcurrentsource(); 74 if (showsourcechanged != null) 75 { 76 showsourcechanged(s); 77 } 78 } 79 80 public override void previouspage() 81 { 82 if (pageindex <= 1) 83 { 84 return; 85 } 86 pageindex--; 87 88 startindex = (pageindex - 1) * pagesize; 89 reloadpage(); 90 var s = getcurrentsource(); 91 if (showsourcechanged != null) 92 { 93 showsourcechanged(s); 94 } 95 } 96 97 public override void nextpage() 98 { 99 if (pageindex >= pagecount) 100 { 101 return; 102 } 103 pageindex++; 104 startindex = (pageindex - 1) * pagesize; 105 reloadpage(); 106 var s = getcurrentsource(); 107 if (showsourcechanged != null) 108 { 109 showsourcechanged(s); 110 } 111 } 112 113 public override void endpage() 114 { 115 if (pageindex == pagecount) 116 return; 117 pageindex = pagecount; 118 startindex = (pageindex - 1) * pagesize; 119 reloadpage(); 120 var s = getcurrentsource(); 121 if (showsourcechanged != null) 122 { 123 showsourcechanged(s); 124 } 125 } 126 127 private void resetpagecount() 128 { 129 if (pagesize > 0) 130 { 131 pagecount = m_datasource.count / m_intpagesize + (m_datasource.count % m_intpagesize > 0 ? 1 : 0); 132 } 133 txtpage.maxvalue = pagecount; 134 txtpage.minvalue = 1; 135 reloadpage(); 136 } 137 138 private void reloadpage() 139 { 140 try 141 { 142 controlhelper.freezecontrol(tablelayoutpanel1, true); 143 list<int> lst = new list<int>(); 144 145 if (pagecount <= 9) 146 { 147 for (var i = 1; i <= pagecount; i++) 148 { 149 lst.add(i); 150 } 151 } 152 else 153 { 154 if (this.pageindex <= 6) 155 { 156 for (var i = 1; i <= 7; i++) 157 { 158 lst.add(i); 159 } 160 lst.add(-1); 161 lst.add(pagecount); 162 } 163 else if (this.pageindex > pagecount - 6) 164 { 165 lst.add(1); 166 lst.add(-1); 167 for (var i = pagecount - 6; i <= pagecount; i++) 168 { 169 lst.add(i); 170 } 171 } 172 else 173 { 174 lst.add(1); 175 lst.add(-1); 176 var begin = pageindex - 2; 177 var end = pageindex + 2; 178 if (end > pagecount) 179 { 180 end = pagecount; 181 begin = end - 4; 182 if (pageindex - begin < 2) 183 { 184 begin = begin - 1; 185 } 186 } 187 else if (end + 1 == pagecount) 188 { 189 end = pagecount; 190 } 191 for (var i = begin; i <= end; i++) 192 { 193 lst.add(i); 194 } 195 if (end != pagecount) 196 { 197 lst.add(-1); 198 lst.add(pagecount); 199 } 200 } 201 } 202 203 for (int i = 0; i < 9; i++) 204 { 205 ucbtnext c = (ucbtnext)this.tablelayoutpanel1.controls.find("p" + (i + 1), false)[0]; 206 if (i >= lst.count) 207 { 208 c.visible = false; 209 } 210 else 211 { 212 if (lst[i] == -1) 213 { 214 c.btntext = "..."; 215 c.enabled = false; 216 } 217 else 218 { 219 c.btntext = lst[i].tostring(); 220 c.enabled = true; 221 } 222 c.visible = true; 223 if (lst[i] == pageindex) 224 { 225 c.rectcolor = color.fromargb(255, 77, 59); 226 } 227 else 228 { 229 c.rectcolor = color.fromargb(223, 223, 223); 230 } 231 } 232 } 233 showbtn(pageindex > 1, pageindex < pagecount); 234 } 235 finally 236 { 237 controlhelper.freezecontrol(tablelayoutpanel1, false); 238 } 239 } 240 241 private void page_btnclick(object sender, eventargs e) 242 { 243 pageindex = (sender as ucbtnext).btntext.toint(); 244 startindex = (pageindex - 1) * pagesize; 245 reloadpage(); 246 var s = getcurrentsource(); 247 248 if (showsourcechanged != null) 249 { 250 showsourcechanged(s); 251 } 252 } 253 254 protected override void showbtn(bool blnleftbtn, bool blnrightbtn) 255 { 256 btnfirst.enabled = btnprevious.enabled = blnleftbtn; 257 btnnext.enabled = btnend.enabled = blnrightbtn; 258 } 259 260 private void btnfirst_btnclick(object sender, eventargs e) 261 { 262 firstpage(); 263 } 264 265 private void btnprevious_btnclick(object sender, eventargs e) 266 { 267 previouspage(); 268 } 269 270 private void btnnext_btnclick(object sender, eventargs e) 271 { 272 nextpage(); 273 } 274 275 private void btnend_btnclick(object sender, eventargs e) 276 { 277 endpage(); 278 } 279 280 private void btntopage_btnclick(object sender, eventargs e) 281 { 282 if (!string.isnullorempty(txtpage.inputtext)) 283 { 284 pageindex = txtpage.inputtext.toint(); 285 startindex = (pageindex - 1) * pagesize; 286 reloadpage(); 287 var s = getcurrentsource(); 288 if (showsourcechanged != null) 289 { 290 showsourcechanged(s); 291 } 292 } 293 } 294 295 } 296 }
1 namespace hzh_controls.controls.list 2 { 3 partial class ucpagercontrol2 4 { 5 /// <summary> 6 /// 必需的设计器变量。 7 /// </summary> 8 private system.componentmodel.icontainer components = null; 9 10 /// <summary> 11 /// 清理所有正在使用的资源。 12 /// </summary> 13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> 14 protected override void dispose(bool disposing) 15 { 16 if (disposing && (components != null)) 17 { 18 components.dispose(); 19 } 20 base.dispose(disposing); 21 } 22 23 #region 组件设计器生成的代码 24 25 /// <summary> 26 /// 设计器支持所需的方法 - 不要 27 /// 使用代码编辑器修改此方法的内容。 28 /// </summary> 29 private void initializecomponent() 30 { 31 this.btnfirst = new hzh_controls.controls.ucbtnext(); 32 this.btnprevious = new hzh_controls.controls.ucbtnext(); 33 this.tablelayoutpanel1 = new system.windows.forms.tablelayoutpanel(); 34 this.p9 = new hzh_controls.controls.ucbtnext(); 35 this.p1 = new hzh_controls.controls.ucbtnext(); 36 this.btntopage = new hzh_controls.controls.ucbtnext(); 37 this.btnend = new hzh_controls.controls.ucbtnext(); 38 this.btnnext = new hzh_controls.controls.ucbtnext(); 39 this.p8 = new hzh_controls.controls.ucbtnext(); 40 this.p7 = new hzh_controls.controls.ucbtnext(); 41 this.p6 = new hzh_controls.controls.ucbtnext(); 42 this.p5 = new hzh_controls.controls.ucbtnext(); 43 this.p4 = new hzh_controls.controls.ucbtnext(); 44 this.p3 = new hzh_controls.controls.ucbtnext(); 45 this.p2 = new hzh_controls.controls.ucbtnext(); 46 this.txtpage = new hzh_controls.controls.uctextboxex(); 47 this.tablelayoutpanel1.suspendlayout(); 48 this.suspendlayout(); 49 // 50 // btnfirst 51 // 52 this.btnfirst.backcolor = system.drawing.color.white; 53 this.btnfirst.btnbackcolor = system.drawing.color.white; 54 this.btnfirst.btnfont = new system.drawing.font("微软雅黑", 9f); 55 this.btnfirst.btnforecolor = system.drawing.color.gray; 56 this.btnfirst.btntext = "<<"; 57 this.btnfirst.conerradius = 5; 58 this.btnfirst.cursor = system.windows.forms.cursors.hand; 59 this.btnfirst.dock = system.windows.forms.dockstyle.fill; 60 this.btnfirst.fillcolor = system.drawing.color.white; 61 this.btnfirst.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 62 this.btnfirst.isradius = true; 63 this.btnfirst.isshowrect = true; 64 this.btnfirst.isshowtips = false; 65 this.btnfirst.location = new system.drawing.point(5, 5); 66 this.btnfirst.margin = new system.windows.forms.padding(5); 67 this.btnfirst.name = "btnfirst"; 68 this.btnfirst.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 69 this.btnfirst.rectwidth = 1; 70 this.btnfirst.size = new system.drawing.size(30, 30); 71 this.btnfirst.tabindex = 0; 72 this.btnfirst.tabstop = false; 73 this.btnfirst.tipstext = ""; 74 this.btnfirst.btnclick += new system.eventhandler(this.btnfirst_btnclick); 75 // 76 // btnprevious 77 // 78 this.btnprevious.backcolor = system.drawing.color.white; 79 this.btnprevious.btnbackcolor = system.drawing.color.white; 80 this.btnprevious.btnfont = new system.drawing.font("微软雅黑", 9f); 81 this.btnprevious.btnforecolor = system.drawing.color.gray; 82 this.btnprevious.btntext = "<"; 83 this.btnprevious.conerradius = 5; 84 this.btnprevious.cursor = system.windows.forms.cursors.hand; 85 this.btnprevious.dock = system.windows.forms.dockstyle.fill; 86 this.btnprevious.fillcolor = system.drawing.color.white; 87 this.btnprevious.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 88 this.btnprevious.isradius = true; 89 this.btnprevious.isshowrect = true; 90 this.btnprevious.isshowtips = false; 91 this.btnprevious.location = new system.drawing.point(45, 5); 92 this.btnprevious.margin = new system.windows.forms.padding(5); 93 this.btnprevious.name = "btnprevious"; 94 this.btnprevious.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 95 this.btnprevious.rectwidth = 1; 96 this.btnprevious.size = new system.drawing.size(30, 30); 97 this.btnprevious.tabindex = 1; 98 this.btnprevious.tabstop = false; 99 this.btnprevious.tipstext = ""; 100 this.btnprevious.btnclick += new system.eventhandler(this.btnprevious_btnclick); 101 // 102 // tablelayoutpanel1 103 // 104 this.tablelayoutpanel1.anchor = ((system.windows.forms.anchorstyles)((system.windows.forms.anchorstyles.top | system.windows.forms.anchorstyles.bottom))); 105 this.tablelayoutpanel1.columncount = 15; 106 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 107 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 108 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 109 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 110 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 111 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 112 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 113 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 114 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 115 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 116 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 117 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 118 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 40f)); 119 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 70f)); 120 this.tablelayoutpanel1.columnstyles.add(new system.windows.forms.columnstyle(system.windows.forms.sizetype.absolute, 70f)); 121 this.tablelayoutpanel1.controls.add(this.p9, 10, 0); 122 this.tablelayoutpanel1.controls.add(this.p1, 2, 0); 123 this.tablelayoutpanel1.controls.add(this.btntopage, 14, 0); 124 this.tablelayoutpanel1.controls.add(this.btnend, 12, 0); 125 this.tablelayoutpanel1.controls.add(this.btnnext, 11, 0); 126 this.tablelayoutpanel1.controls.add(this.p8, 9, 0); 127 this.tablelayoutpanel1.controls.add(this.p7, 8, 0); 128 this.tablelayoutpanel1.controls.add(this.p6, 7, 0); 129 this.tablelayoutpanel1.controls.add(this.p5, 6, 0); 130 this.tablelayoutpanel1.controls.add(this.p4, 5, 0); 131 this.tablelayoutpanel1.controls.add(this.p3, 4, 0); 132 this.tablelayoutpanel1.controls.add(this.p2, 3, 0); 133 this.tablelayoutpanel1.controls.add(this.btnprevious, 1, 0); 134 this.tablelayoutpanel1.controls.add(this.btnfirst, 0, 0); 135 this.tablelayoutpanel1.controls.add(this.txtpage, 13, 0); 136 this.tablelayoutpanel1.location = new system.drawing.point(129, 0); 137 this.tablelayoutpanel1.name = "tablelayoutpanel1"; 138 this.tablelayoutpanel1.rowcount = 1; 139 this.tablelayoutpanel1.rowstyles.add(new system.windows.forms.rowstyle(system.windows.forms.sizetype.percent, 100f)); 140 this.tablelayoutpanel1.size = new system.drawing.size(662, 40); 141 this.tablelayoutpanel1.tabindex = 1; 142 // 143 // p9 144 // 145 this.p9.backcolor = system.drawing.color.white; 146 this.p9.btnbackcolor = system.drawing.color.white; 147 this.p9.btnfont = new system.drawing.font("微软雅黑", 9f); 148 this.p9.btnforecolor = system.drawing.color.gray; 149 this.p9.btntext = "9"; 150 this.p9.conerradius = 5; 151 this.p9.cursor = system.windows.forms.cursors.hand; 152 this.p9.dock = system.windows.forms.dockstyle.fill; 153 this.p9.fillcolor = system.drawing.color.white; 154 this.p9.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 155 this.p9.isradius = true; 156 this.p9.isshowrect = true; 157 this.p9.isshowtips = false; 158 this.p9.location = new system.drawing.point(402, 5); 159 this.p9.margin = new system.windows.forms.padding(2, 5, 2, 5); 160 this.p9.name = "p9"; 161 this.p9.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 162 this.p9.rectwidth = 1; 163 this.p9.size = new system.drawing.size(36, 30); 164 this.p9.tabindex = 17; 165 this.p9.tabstop = false; 166 this.p9.tipstext = ""; 167 this.p9.btnclick += new system.eventhandler(this.page_btnclick); 168 // 169 // p1 170 // 171 this.p1.backcolor = system.drawing.color.white; 172 this.p1.btnbackcolor = system.drawing.color.white; 173 this.p1.btnfont = new system.drawing.font("微软雅黑", 9f); 174 this.p1.btnforecolor = system.drawing.color.gray; 175 this.p1.btntext = "1"; 176 this.p1.conerradius = 5; 177 this.p1.cursor = system.windows.forms.cursors.hand; 178 this.p1.dock = system.windows.forms.dockstyle.fill; 179 this.p1.fillcolor = system.drawing.color.white; 180 this.p1.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 181 this.p1.isradius = true; 182 this.p1.isshowrect = true; 183 this.p1.isshowtips = false; 184 this.p1.location = new system.drawing.point(82, 5); 185 this.p1.margin = new system.windows.forms.padding(2, 5, 2, 5); 186 this.p1.name = "p1"; 187 this.p1.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 188 this.p1.rectwidth = 1; 189 this.p1.size = new system.drawing.size(36, 30); 190 this.p1.tabindex = 16; 191 this.p1.tabstop = false; 192 this.p1.tipstext = ""; 193 this.p1.btnclick += new system.eventhandler(this.page_btnclick); 194 // 195 // btntopage 196 // 197 this.btntopage.backcolor = system.drawing.color.white; 198 this.btntopage.btnbackcolor = system.drawing.color.white; 199 this.btntopage.btnfont = new system.drawing.font("微软雅黑", 11f); 200 this.btntopage.btnforecolor = system.drawing.color.gray; 201 this.btntopage.btntext = "跳转"; 202 this.btntopage.conerradius = 5; 203 this.btntopage.cursor = system.windows.forms.cursors.hand; 204 this.btntopage.dock = system.windows.forms.dockstyle.fill; 205 this.btntopage.fillcolor = system.drawing.color.white; 206 this.btntopage.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 207 this.btntopage.isradius = true; 208 this.btntopage.isshowrect = true; 209 this.btntopage.isshowtips = false; 210 this.btntopage.location = new system.drawing.point(595, 5); 211 this.btntopage.margin = new system.windows.forms.padding(5); 212 this.btntopage.name = "btntopage"; 213 this.btntopage.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 214 this.btntopage.rectwidth = 1; 215 this.btntopage.size = new system.drawing.size(62, 30); 216 this.btntopage.tabindex = 15; 217 this.btntopage.tabstop = false; 218 this.btntopage.tipstext = ""; 219 this.btntopage.btnclick += new system.eventhandler(this.btntopage_btnclick); 220 // 221 // btnend 222 // 223 this.btnend.backcolor = system.drawing.color.white; 224 this.btnend.btnbackcolor = system.drawing.color.white; 225 this.btnend.btnfont = new system.drawing.font("微软雅黑", 9f); 226 this.btnend.btnforecolor = system.drawing.color.gray; 227 this.btnend.btntext = ">>"; 228 this.btnend.conerradius = 5; 229 this.btnend.cursor = system.windows.forms.cursors.hand; 230 this.btnend.dock = system.windows.forms.dockstyle.fill; 231 this.btnend.fillcolor = system.drawing.color.white; 232 this.btnend.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 233 this.btnend.isradius = true; 234 this.btnend.isshowrect = true; 235 this.btnend.isshowtips = false; 236 this.btnend.location = new system.drawing.point(485, 5); 237 this.btnend.margin = new system.windows.forms.padding(5); 238 this.btnend.name = "btnend"; 239 this.btnend.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 240 this.btnend.rectwidth = 1; 241 this.btnend.size = new system.drawing.size(30, 30); 242 this.btnend.tabindex = 13; 243 this.btnend.tabstop = false; 244 this.btnend.tipstext = ""; 245 this.btnend.btnclick += new system.eventhandler(this.btnend_btnclick); 246 // 247 // btnnext 248 // 249 this.btnnext.backcolor = system.drawing.color.white; 250 this.btnnext.btnbackcolor = system.drawing.color.white; 251 this.btnnext.btnfont = new system.drawing.font("微软雅黑", 9f); 252 this.btnnext.btnforecolor = system.drawing.color.gray; 253 this.btnnext.btntext = ">"; 254 this.btnnext.conerradius = 5; 255 this.btnnext.cursor = system.windows.forms.cursors.hand; 256 this.btnnext.dock = system.windows.forms.dockstyle.fill; 257 this.btnnext.fillcolor = system.drawing.color.white; 258 this.btnnext.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 259 this.btnnext.isradius = true; 260 this.btnnext.isshowrect = true; 261 this.btnnext.isshowtips = false; 262 this.btnnext.location = new system.drawing.point(445, 5); 263 this.btnnext.margin = new system.windows.forms.padding(5); 264 this.btnnext.name = "btnnext"; 265 this.btnnext.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 266 this.btnnext.rectwidth = 1; 267 this.btnnext.size = new system.drawing.size(30, 30); 268 this.btnnext.tabindex = 12; 269 this.btnnext.tabstop = false; 270 this.btnnext.tipstext = ""; 271 this.btnnext.btnclick += new system.eventhandler(this.btnnext_btnclick); 272 // 273 // p8 274 // 275 this.p8.backcolor = system.drawing.color.white; 276 this.p8.btnbackcolor = system.drawing.color.white; 277 this.p8.btnfont = new system.drawing.font("微软雅黑", 9f); 278 this.p8.btnforecolor = system.drawing.color.gray; 279 this.p8.btntext = "8"; 280 this.p8.conerradius = 5; 281 this.p8.cursor = system.windows.forms.cursors.hand; 282 this.p8.dock = system.windows.forms.dockstyle.fill; 283 this.p8.fillcolor = system.drawing.color.white; 284 this.p8.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 285 this.p8.isradius = true; 286 this.p8.isshowrect = true; 287 this.p8.isshowtips = false; 288 this.p8.location = new system.drawing.point(362, 5); 289 this.p8.margin = new system.windows.forms.padding(2, 5, 2, 5); 290 this.p8.name = "p8"; 291 this.p8.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 292 this.p8.rectwidth = 1; 293 this.p8.size = new system.drawing.size(36, 30); 294 this.p8.tabindex = 8; 295 this.p8.tabstop = false; 296 this.p8.tipstext = ""; 297 this.p8.btnclick += new system.eventhandler(this.page_btnclick); 298 // 299 // p7 300 // 301 this.p7.backcolor = system.drawing.color.white; 302 this.p7.btnbackcolor = system.drawing.color.white; 303 this.p7.btnfont = new system.drawing.font("微软雅黑", 9f); 304 this.p7.btnforecolor = system.drawing.color.gray; 305 this.p7.btntext = "7"; 306 this.p7.conerradius = 5; 307 this.p7.cursor = system.windows.forms.cursors.hand; 308 this.p7.dock = system.windows.forms.dockstyle.fill; 309 this.p7.fillcolor = system.drawing.color.white; 310 this.p7.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 311 this.p7.isradius = true; 312 this.p7.isshowrect = true; 313 this.p7.isshowtips = false; 314 this.p7.location = new system.drawing.point(322, 5); 315 this.p7.margin = new system.windows.forms.padding(2, 5, 2, 5); 316 this.p7.name = "p7"; 317 this.p7.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 318 this.p7.rectwidth = 1; 319 this.p7.size = new system.drawing.size(36, 30); 320 this.p7.tabindex = 7; 321 this.p7.tabstop = false; 322 this.p7.tipstext = ""; 323 this.p7.btnclick += new system.eventhandler(this.page_btnclick); 324 // 325 // p6 326 // 327 this.p6.backcolor = system.drawing.color.white; 328 this.p6.btnbackcolor = system.drawing.color.white; 329 this.p6.btnfont = new system.drawing.font("微软雅黑", 9f); 330 this.p6.btnforecolor = system.drawing.color.gray; 331 this.p6.btntext = "6"; 332 this.p6.conerradius = 5; 333 this.p6.cursor = system.windows.forms.cursors.hand; 334 this.p6.dock = system.windows.forms.dockstyle.fill; 335 this.p6.fillcolor = system.drawing.color.white; 336 this.p6.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 337 this.p6.isradius = true; 338 this.p6.isshowrect = true; 339 this.p6.isshowtips = false; 340 this.p6.location = new system.drawing.point(282, 5); 341 this.p6.margin = new system.windows.forms.padding(2, 5, 2, 5); 342 this.p6.name = "p6"; 343 this.p6.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 344 this.p6.rectwidth = 1; 345 this.p6.size = new system.drawing.size(36, 30); 346 this.p6.tabindex = 6; 347 this.p6.tabstop = false; 348 this.p6.tipstext = ""; 349 this.p6.btnclick += new system.eventhandler(this.page_btnclick); 350 // 351 // p5 352 // 353 this.p5.backcolor = system.drawing.color.white; 354 this.p5.btnbackcolor = system.drawing.color.white; 355 this.p5.btnfont = new system.drawing.font("微软雅黑", 9f); 356 this.p5.btnforecolor = system.drawing.color.gray; 357 this.p5.btntext = "5"; 358 this.p5.conerradius = 5; 359 this.p5.cursor = system.windows.forms.cursors.hand; 360 this.p5.dock = system.windows.forms.dockstyle.fill; 361 this.p5.fillcolor = system.drawing.color.white; 362 this.p5.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 363 this.p5.isradius = true; 364 this.p5.isshowrect = true; 365 this.p5.isshowtips = false; 366 this.p5.location = new system.drawing.point(242, 5); 367 this.p5.margin = new system.windows.forms.padding(2, 5, 2, 5); 368 this.p5.name = "p5"; 369 this.p5.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 370 this.p5.rectwidth = 1; 371 this.p5.size = new system.drawing.size(36, 30); 372 this.p5.tabindex = 5; 373 this.p5.tabstop = false; 374 this.p5.tipstext = ""; 375 this.p5.btnclick += new system.eventhandler(this.page_btnclick); 376 // 377 // p4 378 // 379 this.p4.backcolor = system.drawing.color.white; 380 this.p4.btnbackcolor = system.drawing.color.white; 381 this.p4.btnfont = new system.drawing.font("微软雅黑", 9f); 382 this.p4.btnforecolor = system.drawing.color.gray; 383 this.p4.btntext = "4"; 384 this.p4.conerradius = 5; 385 this.p4.cursor = system.windows.forms.cursors.hand; 386 this.p4.dock = system.windows.forms.dockstyle.fill; 387 this.p4.fillcolor = system.drawing.color.white; 388 this.p4.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 389 this.p4.isradius = true; 390 this.p4.isshowrect = true; 391 this.p4.isshowtips = false; 392 this.p4.location = new system.drawing.point(202, 5); 393 this.p4.margin = new system.windows.forms.padding(2, 5, 2, 5); 394 this.p4.name = "p4"; 395 this.p4.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 396 this.p4.rectwidth = 1; 397 this.p4.size = new system.drawing.size(36, 30); 398 this.p4.tabindex = 4; 399 this.p4.tabstop = false; 400 this.p4.tipstext = ""; 401 this.p4.btnclick += new system.eventhandler(this.page_btnclick); 402 // 403 // p3 404 // 405 this.p3.backcolor = system.drawing.color.white; 406 this.p3.btnbackcolor = system.drawing.color.white; 407 this.p3.btnfont = new system.drawing.font("微软雅黑", 9f); 408 this.p3.btnforecolor = system.drawing.color.gray; 409 this.p3.btntext = "3"; 410 this.p3.conerradius = 5; 411 this.p3.cursor = system.windows.forms.cursors.hand; 412 this.p3.dock = system.windows.forms.dockstyle.fill; 413 this.p3.fillcolor = system.drawing.color.white; 414 this.p3.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 415 this.p3.isradius = true; 416 this.p3.isshowrect = true; 417 this.p3.isshowtips = false; 418 this.p3.location = new system.drawing.point(162, 5); 419 this.p3.margin = new system.windows.forms.padding(2, 5, 2, 5); 420 this.p3.name = "p3"; 421 this.p3.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 422 this.p3.rectwidth = 1; 423 this.p3.size = new system.drawing.size(36, 30); 424 this.p3.tabindex = 3; 425 this.p3.tabstop = false; 426 this.p3.tipstext = ""; 427 this.p3.btnclick += new system.eventhandler(this.page_btnclick); 428 // 429 // p2 430 // 431 this.p2.backcolor = system.drawing.color.white; 432 this.p2.btnbackcolor = system.drawing.color.white; 433 this.p2.btnfont = new system.drawing.font("微软雅黑", 9f); 434 this.p2.btnforecolor = system.drawing.color.gray; 435 this.p2.btntext = "2"; 436 this.p2.conerradius = 5; 437 this.p2.cursor = system.windows.forms.cursors.hand; 438 this.p2.dock = system.windows.forms.dockstyle.fill; 439 this.p2.fillcolor = system.drawing.color.white; 440 this.p2.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 441 this.p2.isradius = true; 442 this.p2.isshowrect = true; 443 this.p2.isshowtips = false; 444 this.p2.location = new system.drawing.point(122, 5); 445 this.p2.margin = new system.windows.forms.padding(2, 5, 2, 5); 446 this.p2.name = "p2"; 447 this.p2.rectcolor = system.drawing.color.fromargb(((int)(((byte)(223)))), ((int)(((byte)(223)))), ((int)(((byte)(223))))); 448 this.p2.rectwidth = 1; 449 this.p2.size = new system.drawing.size(36, 30); 450 this.p2.tabindex = 2; 451 this.p2.tabstop = false; 452 this.p2.tipstext = ""; 453 this.p2.btnclick += new system.eventhandler(this.page_btnclick); 454 // 455 // txtpage 456 // 457 this.txtpage.backcolor = system.drawing.color.transparent; 458 this.txtpage.conerradius = 5; 459 this.txtpage.cursor = system.windows.forms.cursors.ibeam; 460 this.txtpage.declength = 2; 461 this.txtpage.fillcolor = system.drawing.color.empty; 462 this.txtpage.font = new system.drawing.font("微软雅黑", 15f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 463 this.txtpage.forecolor = system.drawing.color.gray; 464 this.txtpage.inputtext = ""; 465 this.txtpage.inputtype = hzh_controls.textinputtype.positiveinteger; 466 this.txtpage.isfocuscolor = true; 467 this.txtpage.isradius = true; 468 this.txtpage.isshowclearbtn = false; 469 this.txtpage.isshowkeyboard = false; 470 this.txtpage.isshowrect = true; 471 this.txtpage.isshowsearchbtn = false; 472 this.txtpage.keyboardtype = hzh_controls.controls.keyboardtype.uckeyborderall_en; 473 this.txtpage.location = new system.drawing.point(524, 5); 474 this.txtpage.margin = new system.windows.forms.padding(4, 5, 4, 5); 475 this.txtpage.maxvalue = new decimal(new int[] { 476 1000000, 477 0, 478 0, 479 0}); 480 this.txtpage.minvalue = new decimal(new int[] { 481 1000000, 482 0, 483 0, 484 -2147483648}); 485 this.txtpage.name = "txtpage"; 486 this.txtpage.padding = new system.windows.forms.padding(5); 487 this.txtpage.promptcolor = system.drawing.color.silver; 488 this.txtpage.promptfont = new system.drawing.font("微软雅黑", 13f, system.drawing.fontstyle.regular, system.drawing.graphicsunit.pixel); 489 this.txtpage.prompttext = "页码"; 490 this.txtpage.rectcolor = system.drawing.color.fromargb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); 491 this.txtpage.rectwidth = 1; 492 this.txtpage.regexpattern = ""; 493 this.txtpage.size = new system.drawing.size(62, 30); 494 this.txtpage.tabindex = 14; 495 // 496 // ucpagercontrol2 497 // 498 this.autoscalemode = system.windows.forms.autoscalemode.none; 499 this.backcolor = system.drawing.color.white; 500 this.controls.add(this.tablelayoutpanel1); 501 this.name = "ucpagercontrol2"; 502 this.size = new system.drawing.size(921, 41); 503 this.tablelayoutpanel1.resumelayout(false); 504 this.resumelayout(false); 505 506 } 507 508 #endregion 509 510 private ucbtnext btnfirst; 511 private ucbtnext btnprevious; 512 private system.windows.forms.tablelayoutpanel tablelayoutpanel1; 513 private ucbtnext btnend; 514 private ucbtnext btnnext; 515 private ucbtnext p8; 516 private ucbtnext p7; 517 private ucbtnext p6; 518 private ucbtnext p5; 519 private ucbtnext p4; 520 private ucbtnext p3; 521 private ucbtnext p2; 522 private ucbtnext btntopage; 523 private uctextboxex txtpage; 524 private ucbtnext p9; 525 private ucbtnext p1; 526 } 527 }
用处及效果
最后的话
如果你喜欢的话,请到 点个星 星吧