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)
| 归档时间: |
|
| 查看次数: |
4810 次 |
| 最近记录: |