有时子窗体的操作需要实时调用父窗体中的控件操作,比如在父窗体的文本框中显示子窗体中的输出:
主窗体:
MainForm.cs:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SubForm SubForm = new SubForm();
// 3.将ChangeTextVal加入到委托事件中
// 等效于:
// SubForm.ChangeTextVal += ChangeTextVal;
SubForm.ChangeTextVal += new DelegateChangeTextVal(ChangeTextVal);
SubForm.ShowDialog();
}

这篇博客介绍了如何在C#编程中,通过使用委托来实现在子窗体操作时动态更新父窗体的控件,特别是文本框的内容。这种技术常见于需要在子窗体中进行某些处理并反馈结果到父窗体的场景。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



