winfrom子窗口点击怎么更新父窗口
1个回答
展开全部
可以用委托实现。
三个文件Main窗体,SubMain窗体,CommonDelegate类
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Main : Form
{
private void ChangeLableTextMethod(string txt)
{
lblTestTxt.Text = txt;
}
public Main()
{
InitializeComponent();
}
private void btnClick_Click(object sender, EventArgs e)
{
new SubForm(ChangeLableTextMethod).ShowDialog();
}
}
}
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class SubForm : Form
{
private ChangeLabelTxtDelegate changeLabelTxtDelegate;
public SubForm(ChangeLabelTxtDelegate changeLabelTxtDelegate)
{
InitializeComponent();
//
this.changeLabelTxtDelegate = changeLabelTxtDelegate;
}
private void btnGo_Click(object sender, EventArgs e)
{
changeLabelTxtDelegate(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss:fff"));
}
}
}
public delegate void ChangeLabelTxtDelegate(string txt);
可以设断点看看这个是怎么运行的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询