【发布时间】:2009-11-18 14:52:25
【问题描述】:
我正在尝试将Textbox.Text 绑定到Form.Text(设置表单的标题)。
绑定本身有效。但是,在我移动整个表单之前,标题不会更新。
如何在不移动表单的情况下更新Form.Text?我希望在文本框中输入内容时直接更新 Form.Text。
编辑;我在由 ToolStripTextbox 触发的 TextChanged 事件中设置了表单的标题:
public partial class ProjectForm : Form
{
public ProjectForm()
{
// my code contains all sorts of code here,
// but nothing that has something to do with the text.
}
}
private void projectName_TextChanged_1(object sender, EventArgs e)
{
this.Text = projectName.TextBox.Text;
}
还有数据绑定版本:
public partial class ProjectForm : Form
{
public ProjectForm()
{
this.projectName.TextBox.DataBindings.Add("Text", this, "Text", true, DataSourceUpdateMode.OnValidation);
}
}
编辑 2:我知道我忘了提一些事情。不知道它是否添加了任何东西,但我的应用程序是 MDI 应用程序。标题变化的部分是:
ApplicationName [THIS CHANGES, BUT ONLY AFTER MOVING/RESIZING]
【问题讨论】:
-
真的很奇怪。直接设置 Form.Text 属性时,我从未观察到任何重绘问题。你能和我们分享一些代码sn-p吗?
标签: c# winforms data-binding textbox title