1、定义调用一个父类IParentUctonrol:

View Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClinicDoctor.Class
{
public interface IParentUseControl
{
/// <summary>
/// 分页功能方法。获取数据
/// </summary>
/// <param name="nPagenum">显示的当前页码</param>
/// <param name="ShowNum">一页显示多少条数据</param>
void FaceData(int nPagenum,int ShowNum);
}
}



2、创建自定义控件UcPaging,代码:

View Code
  1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using ClinicDoctor.Class;
10
11 namespace ClinicDoctor.UserControls
12 {
13 public partial class ucPagging : UserControl
14 {
15 int _Pagenum;
16 /// <summary>
17 /// 当前页码
18 /// </summary>
19 public int Pagenum
20 {
21 get { return _Pagenum; }
22 set { _Pagenum = value; }
23 }
24 int _Pages;
25 /// <summary>
26 /// 总页数
27 /// </summary>
28 public int Pages
29 {
30 get { return _Pages; }
31 set { _Pages = value; }
32 }
33 /// <summary>
34 /// 显示的数据信息
35 /// </summary>
36 public Label LbDataInfo
37 {
38 get { return lbDataInfo; }
39 set { lbDataInfo = value; }
40 }
41 /// <summary>
42 /// 显示多少条选择
43 /// </summary>
44 public ComboBox ComboBox1
45 {
46 get { return comboBox1; }
47 }
48 /// <summary>
49 /// 首页
50 /// </summary>
51 public Button Button1
52 {
53 get { return button1; }
54 }
55 /// <summary>
56 /// 上一页
57 /// </summary>
58 public Button Button2
59 {
60 get { return button2; }
61 }
62 /// <summary>
63 /// 下一页
64 /// </summary>
65 public Button Button3
66 {
67 get { return button3; }
68 }
69 /// <summary>
70 /// 末页
71 /// </summary>
72 public Button Button4
73 {
74 get { return button4; }
75 }
76
77 public ucPagging()
78 {
79 InitializeComponent();
80 }
81 void ClickEvent(object sender,EventArgs e)
82 {
83 Control control = this.ActiveControl;
84 switch (control.Name)
85 {
86 case "button1":
87 case "comboBox1":
88 Pagenum = 1;
89 break;
90 case "button2":
91 if (Pagenum > 1)
92 Pagenum -= 1;
93 break;
94 case "button3":
95 if (Pagenum < Pages)
96 Pagenum += 1;
97 break;
98 case "button4":
99 Pagenum = Pages;
100 break;
101 }
102 IParentUseControl fs = (IParentUseControl)this.Parent;
103 fs.FaceData(Pagenum, int.Parse(comboBox1.Text));
104 }
105 }
106 }

3、窗体添加分页控件,获取数据,给分页控件属性Pages 总页数赋值。

posted on 2012-01-09 14:30  xalyf  阅读(260)  评论(0编辑  收藏  举报