我现在重新设了一下,当界面的状态改变时,同时用手动的方式将背景色改成灰色.
即当设置控件的Enabled属性为true时,我将其BackColor属性设为红色,而控件的Enabled属性为false时,我将其BackColor属性设为灰色..
代码如下:
private void controlState(FormState currentState)
{
switch (currentState)
{
case FormState.AddState:
this.tbEID.Enabled = true;
this.tbName.Enabled = true;
this.tbCode.Enabled = true;
this.cbGender.Enabled = true;
this.dtpInFactory.Enabled = true;
this.dtpBirthday.Enabled = true;
this.tbUID.Enabled = true;
this.tbAddress.Enabled = true;
this.tbGuardian.Enabled = true;
this.tbLinkTel.Enabled = true;
this.tbFSchool.Enabled = true;
this.tbSpeciality.Enabled = true;
this.bindingDetail(false); // 清除各控件的数据绑定
// 初始化各控件的值
this.tbEID.Text = "";
this.tbName.Text = "";
this.tbCode.Text = "";
this.cbGender.SelectedValue = 0;
this.dtpInFactory.Value = DateTime.Now;
this.dtpBirthday.Value = new DateTime(DateTime.Now.Year - 16, DateTime.Now.Month, DateTime.Now.Day);
this.tbUID.Text = "";
this.tbAddress.Text = "";
this.tbGuardian.Text = "";
this.tbLinkTel.Text = "";
this.tbFSchool.Text = "";
this.tbSpeciality.Text = "";
// 设置"工号"、"姓名"、"性别"、"出生日期"、"身份证号","入厂日期"明细控件中的背景色,以提示用户该项为必填项
this.tbEID.BackColor = System.Drawing.Color.SkyBlue;
this.tbName.BackColor = System.Drawing.Color.SkyBlue;
this.cbGender.BackColor = System.Drawing.Color.SkyBlue;
this.tbUID.BackColor = System.Drawing.Color.SkyBlue;
break;
case FormState.BrowseState:
this.tbEID.Enabled = false;
this.tbName.Enabled = false;
this.tbCode.Enabled = false;
this.cbGender.Enabled = false;
this.dtpInFactory.Enabled = false;
this.dtpBirthday.Enabled = false;
this.tbUID.Enabled = false;
this.tbAddress.Enabled = false;
this.tbGuardian.Enabled = false;
this.tbLinkTel.Enabled = false;
this.tbFSchool.Enabled = false;
this.tbSpeciality.Enabled = false;
this.bindingDetail(true); // 绑定数据
// 当界面为到浏览状态时,就意味着有可能向表中新增或删除了记录,因此从新设定表中记录数以及记录指针的当前位置
this.RecCount = this.bsEmployee.Count;
this.RecPosition = this.bsEmployee.Position;
// 恢复"工号"、"姓名"、"性别"、"出生日期"、"身份证号","入厂日期"明细控件中的背景色
this.tbEID.BackColor = System.Drawing.SystemColors.Control;
this.tbName.BackColor = System.Drawing.SystemColors.Control;
this.cbGender.BackColor = System.Drawing.SystemColors.Control;
this.tbUID.BackColor = System.Drawing.SystemColors.Control;
break;
case FormState.EditState:
this.tbEID.Enabled = false;
this.tbName.Enabled = true;
this.tbCode.Enabled = true;
this.cbGender.Enabled = true;
this.dtpInFactory.Enabled = true;
this.dtpBirthday.Enabled = true;
this.tbUID.Enabled = true;
this.tbAddress.Enabled = true;
this.tbGuardian.Enabled = true;
this.tbLinkTel.Enabled = true;
this.tbFSchool.Enabled = true;
this.tbSpeciality.Enabled = true;
this.bindingDetail(true); // 绑定数据
// 设置"工号"、"姓名"、"性别"、"出生日期"、"身份证号","入厂日期"明细控件中的背景色,以提示用户该项为必填项
this.tbName.BackColor = System.Drawing.Color.SkyBlue;
this.cbGender.BackColor = System.Drawing.Color.SkyBlue;
this.tbUID.BackColor = System.Drawing.Color.SkyBlue;
break;
default:
break;
}
}
[此贴子已经被作者于2007-2-3 22:19:04编辑过]