这是最奇怪的事情,因为它在某些代码中对我有用,而不是其他代码。以下代码位于子类 TextBox 的类中(注意:我不知道这是否重要,但我将 Text 属性子类化以从私有字段 _realText 设置/获取)
在下面的代码中,第一个 base.Text = this.RealText 工作正常!!!我们还将它设置在该方法 MaskData() 中,并且它有效!!!!那么为什么它在 if(!field.isSecure) 部分中不起作用呢?(查看日志以了解我的意思)。我尝试在 base.Text=temp 之后添加 Invalidate()、Update() 但这没有帮助。
代码:
private void SetupTextInBox()
{
if (isInManualMode)
{
this.ReadOnly = false;
base.Text = this.RealText;
}
else
{
this.ReadOnly = true;
if (!field.IsSecure)
{
string temp = this.RealText;
log.Info("This field is not secure so show it. field=" + field.Variable + " real='" + temp+"'");
base.Text = temp;
log.Info("text value='" + base.Text+"'");
return;
}
else
{
MaskData();
}
}
}
日志
2012-06-30 07:15:51,468 [1] INFO AlpineAccess.Plugins.SecureTalkPlugin.SecureTextControl (null) - This field is not secure so show it. field=1.acc real='2222'
2012-06-30 07:15:51,468 [1] INFO AlpineAccess.Plugins.SecureTalkPlugin.SecureTextControl (null) - text value=''
编辑:请注意,此方法总是从同一个线程调用。它来自服务器通知,告诉我们在其他地方的电话上已按下音调,然后该线程调用 BeginInvoke 将其放入 GUI/控制线程或诸如此类的东西。
上述方法上游的代码是
public void AppendDTMFDigit(string digit)
{
log.Info("specified="+field.MaxSpecified+" someone appending dtmf digit on field=" + field.Variable+" fieldMax="+field.Max+" len="+RealText.Length);
if (field.MaxSpecified && this.RealText.Length >= field.Max)
return; //shortcut out since we can't exceed max digits
BeginInvoke(new MethodInvoker(delegate()
{
this.RealText = this.RealText + digit;
log.Info("new realtext=" + this.RealText);
SetupTextInBox();
}
));
}
更多信息:如果我将所有客户端代码更改为停止使用 Text 属性并使用 RealText 属性,然后停止覆盖 Text 属性,则它可以正常工作。(显然我不希望这样,因为现在我不能只是从我的控件更改为 TextBox 并轻松返回,而无需更改大量引用 RealText 属性的客户端代码......呃,可能不得不忍受这一点。 ...似乎是某种奇怪的错误。
更多信息:让调试器进入其中,这很奇怪。
2 很奇怪的事情。
- 它进入了getter,而不是setter???
- 它进入 MY Text 属性而不是 TextBox 的 Text 属性。
grrrrr,为什么会...听起来像一个主要错误,对吗?我的意思是,base.Text 应该引用超类的基础,对吗?– Dean Hiller 刚刚编辑
添加 Text 方法属性代码
public override string Text
{
get
{
return RealText;
}
set
{
if (value == null)
throw new ArgumentException("Not allowed to set RealText to null. Set to empty string instead");
RealText = value;
}
}