【问题标题】:how can I bind a string property to a ToolStripTextBox?如何将字符串属性绑定到 ToolStripTextBox?
【发布时间】:2011-04-26 19:06:35
【问题描述】:

我相信,我的问题根源在于 TextBoxIBindableComponent,而 ToolStripTextBox 不是。

我正在寻找与ToolStripTextBox 进行简单绑定,如答案here 中所述。

public int Unit {get;set;} 
private void Form1_Load(object sender, EventArgs e) {
  toolStripTextBox1.DataBindings.Add("Text", this, "Unit"); 
} 

目前我正在这样做:

public string SendToEmail {
 get{
  return _sendToEmail.Text;
 }
 set {
  _sendToEmail.Text = value;
 }
}

所以现在我得到了双向同步,但它不是松散耦合的。

问题:是否有一个 .NET 类封装了两个类的属性名称并监视一个或两个方向的变化,(使用反射?)在它们之间推送值?还是有更简单的思考方式?

【问题讨论】:

    标签: c# winforms data-binding


    【解决方案1】:

    使用 ToolStripTextBox 的 TextBox 属性进行数据绑定。这是一个完整的 TextBox 控件,可让您访问所需的 DataBinding。

    // this is NOT the same code as above, note the TextBox property in use.
    this.toolStripTextBox1.TextBox.DataBindings.Add(...);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 2018-09-29
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多