将ShowDialog等内容添加到自定义用户控件中?

Joh*_*n M 5 c# user-controls .net-3.5 winforms

当用户选择按钮时,会向表单添加自定义用户控件.此用户控件提供输入某些值的功能.

在更改主窗体上的值之前,如何等待用户控件完成?

我在考虑这样的事情:

customControl ylc = new customControl();
ylc.Location = new Point(11, 381);
ylc.Parent = this;
ylc.BringToFront();

if(ylc.ShowDialog() == DialogResult.OK)
{
   this.lblSomeText.Text = ylc.PublicPropertyValue
}
Run Code Online (Sandbox Code Playgroud)

UPDATE1

用户控件无法添加到自己的表单中.在某些形式上,它是"嵌入式",在其他形式上,它是根据需要动态创建的.

UPDATE2

这个SO 链接很有帮助.

我的最终解决方案看起来像(我在'完成'时隐藏了用户控件):

customControl ylc = new customControl();
ylc.Location = new Point(11, 381);
ylc.Parent = this;
ylc.BringToFront();
ylc.VisibleChanged += new EventHandler(ylc_VisibleChanged);    
ylc.Show();
Run Code Online (Sandbox Code Playgroud)

然后这段代码进入'Visiblechanged'事件:

if(ylc.ShowDialog() == DialogResult.OK)
{
   this.lblSomeText.Text = ylc.PublicPropertyValue
}
Run Code Online (Sandbox Code Playgroud)

mse*_*ant 6

用户控件真的没有完成吗?我认为通过将用户控件放在自己的窗体上并在其上调用ShowDialog可能会更好地实现您要做的事情.