覆盖OnEnter以禁用格式化输入文本,但会中断数据绑定

时间:2015-12-04 23:20:29

标签: c# data-binding formatting

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);
    }


}

当您输入绑定文本框时,格式应该消失,如果文本再次格式化,则应该离开。当我尝试这个代码数据绑定时。

0 个答案:

没有答案