0

我有一个用户控件,它根据两个文本字段(名字和姓氏)组合一个字符串,我想让另一个标签使用它来表示“你的名字是 FIRSTNAME LASTNAME”。

虽然我可以看到用户控件输出的公共字符串,但我找不到指定用户控件何时有新输入的事件。

如果我能做类似的事情那就太好了...

    private void userControl_Update()
    {
        lblYourName.Text = String.Format("Your name is {0}", userControl.name);
    }

但我不知道该怎么做。

我将 VB2012 与 Visual c# 和表单一起使用。

谢谢你的帮助。

4

1 回答 1

1

看起来您正在使用 WinForms。

在这种情况下,我相信您正在寻找的事件是TextChanged事件:

// Set using the visual Form Designer, generally
lblName.TextChanged += lblName_TextChanged;

// Later, the event handler
private void lblName_TextChanged(object sender, EventArgs e)
{
    lblYourName.Text = String.Format("Your name is {0}", lblName.Text);
}
于 2013-09-17T00:28:04.650 回答