程序 namespace dotnet { using system; using system.data; using system.drawing; using system.web; using system.web.ui.webcontrols; using system.web.ui.htmlcontrols;
/// <summary> /// mycontrol 的摘要说明。 /// </summary> public class mycontrol : system.web.ui.usercontrol {
private viewtypes _mytypes; private string _myvalue = ""; private int _mymaxnumber=0; private int _myminnumber=0; //我们定义的属性,_mytypes枚举值,_mymaxnumber,_myminnumber为3个控件绑定的最小值,和最大值. public string myvalue //这里暂时不会用到 {
get { return _myvalue; } set { _myvalue = value; } } public enum viewtypes//定义3个控件的枚举值 { drop, check, radio } public viewtypes mytypes { get { return _mytypes; } set { _mytypes= value; } } public int mymaxnumber { get { return _mymaxnumber; } set { _mymaxnumber=value; } } public int myminnumber { get { return _myminnumber; } set { _myminnumber=value; } }
/* 以上myvalue,mytypes,mymaxnumber,myminnumber四个模块都是给控件定义的四个属性,在这里面get{}部分在这里有读取值的作用,而set{}部分是往属性里面写值,。注意:他们前面的要用public定义,绝对不能用private,protected定义这里涉及到一个见级性问题,不明白的朋友请参阅相关书籍,还一个要注意的地方是我们定义的属性值不能和上面声明的变量名一样。例如: private int _intcount; public int _intcount//切忌,这里千万不要和上面声明的变量是一样的,在这里是错误的,要改成public int intcount { get{return _intcount;} set{_intcount=value;} } 在这里有个技巧,再声明变量的时候,可以给第一个字母加上下划线,或者再定义属性的时候的时候第一个字母大写,比如private int intcount,然后就是public int intcount。 我们在来说一下这几个属性是干什么用的:mytypes是显示哪种控件(在这里定义了一个枚举,里面有三个值,分别指的是下拉列表框,复选框,和单选按钮,别忘了在上面声明哦 private viewtypes _mytypes);mymaxnumber,myminnumber是绑定到控件上最大值和最小值; */