是不是像下面这种: class user { public CustomerAttribute Telephone {get;set;} } class CustomerAttribute { public String TelephoneNumber {get;set;} Public Color BackColor {get;set;} //.......... }
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] [Serializable] public class DBProperty : Attribute {
int maxLength; ............. /// <summary> /// 数据列最大长度 /// </summary> public int MaxLength { get { return maxLength; } set { maxLength = value; } } }public class Contact { #region field int n_ID; string s_NAME; #endregion #region property [DBProperty(Name="N_ID",IsAutoIncrease=true,IsPrimaryKey=true,OrmDBType= ORMEnum.DataType.INT)] public int N_ID { get { return n_ID; } set { n_ID = value; } } [DBProperty(Name = "S_NAME",OrmDBType = ORMEnum.DataType.STRING,MaxLength=10,NotRepeat=true,NotNull=true)] public string S_NAME { get { return s_NAME; } set { s_NAME = value; } } #endregion }绑定的时候再对这个东西进行解释,即可!
我觉得你的问题的是双向绑定的问题,就用你上面说的backcolor与Telephone来说, public class User { public Color ErrorColor//与Textbox的backcolor属性绑定 { get; set; } public string Telephone { get; set { if(value判断格式是不是正确的) 不正确的话改变this.ErrorColor = Color.Red; } } }将User类与TextBox控件的两个属性绑定,当text属性发生改变时,user类的telephone属性也会发生改变,这时你会在里面判断用户输入的格式是不是正确的,如果不正确就修改ErrorColor属性值,而ErrorColor属性又与TextBox控件的backcolor属性绑定,所以errorcolor的改变就会改变Textbox控件的颜色。 具体实现不知道,但记得在那里看到过
要么你就telephone和id不用简单类型string和id
自己定义类,继承要么,自己继承Attribute写自定义特性,但是,自定义特性和backcolor是完全不同的
要么你就telephone和id不用简单类型string和id
自己定义类,继承要么,自己继承Attribute写自定义特性,但是,自定义特性和backcolor是完全不同的
class user
{
public CustomerAttribute Telephone
{get;set;}
}
class CustomerAttribute
{
public String TelephoneNumber
{get;set;}
Public Color BackColor
{get;set;}
//..........
}
[Serializable]
public class DBProperty : Attribute
{
int maxLength;
.............
/// <summary>
/// 数据列最大长度
/// </summary>
public int MaxLength
{
get { return maxLength; }
set { maxLength = value; }
}
}public class Contact
{
#region field
int n_ID;
string s_NAME;
#endregion
#region property
[DBProperty(Name="N_ID",IsAutoIncrease=true,IsPrimaryKey=true,OrmDBType= ORMEnum.DataType.INT)]
public int N_ID
{
get { return n_ID; }
set { n_ID = value; }
}
[DBProperty(Name = "S_NAME",OrmDBType = ORMEnum.DataType.STRING,MaxLength=10,NotRepeat=true,NotNull=true)]
public string S_NAME
{
get { return s_NAME; }
set { s_NAME = value; }
}
#endregion }绑定的时候再对这个东西进行解释,即可!
public class User
{
public Color ErrorColor//与Textbox的backcolor属性绑定
{
get;
set;
}
public string Telephone
{
get;
set
{
if(value判断格式是不是正确的)
不正确的话改变this.ErrorColor = Color.Red;
}
}
}将User类与TextBox控件的两个属性绑定,当text属性发生改变时,user类的telephone属性也会发生改变,这时你会在里面判断用户输入的格式是不是正确的,如果不正确就修改ErrorColor属性值,而ErrorColor属性又与TextBox控件的backcolor属性绑定,所以errorcolor的改变就会改变Textbox控件的颜色。
具体实现不知道,但记得在那里看到过