1.首先在B类中定义静态成员
public static B b=null;
其次,在B类构造函数中给静态成员初始化
- public B()
- {
- B = this;
- InitializeComponent();
- }
在A类中,调用更新B类控件的方法
B.b.Method("已通过");
2.如果当前方法所在的线程不是UI线程,需要使用Invoke方法将Method方法委托给UI线程执行。
- private void Method(string strMsg)
- {
- if (tb_con.InvokeRequired)
- {
- tb_con.Invoke(new MethodInvoker(() => Method(strMsg)));
- }
- else
- {
- tb_con.Text += Environment.NewLine + strMsg;
- }
- }