本文转载:http://www.cnblogs.com/LinFx/archive/2011/12/23/2299895.html
1.自定义控件, 和接口
interface IModify { bool IsModified { get; } }
class TextBoxEx : TextBox, IModify { private bool isModified = false;
public bool IsModified { get { return isModified; } }
protected override void OnTextChanged(EventArgs e) { this.isModified = true; base.OnTextChanged(e); } }
2.使用方法
private void button1_Click(object sender, EventArgs e) { var b = IsModify(this); Text = b.ToString(); }
private bool IsModify(Control ctrl) { foreach (Control control in ctrl.Controls) { if (control.Controls.Count > 0) return IsModify(control); if (control is IModify) { if (((IModify)control).IsModified) return true; } } return false; }
|
请发表评论