public class CustomTextBox
{
protected override void OnEnter(EventArgs e)
{
if (this.DataBindings.Count > 0)
{
this.cancelvalidating = true;
this.DataBindings[0].FormattingEnabled = false;
this.cancelvalidating = false;
}
OldText = this.Text;
base.OnEnter(e);
}
protected override void OnLeave(EventArgs e)
{
if (this.DataBindings.Count > 0)
{
this.cancelvalidating = true;
this.DataBindings[0].FormattingEnabled = true;
this.cancelvalidating = false;
}
base.OnLeave(e);
}
}
当您输入绑定文本框时,格式应该消失,如果文本再次格式化,则应该离开。当我尝试这个代码数据绑定时。