C# 窗口之间传递数据实时显示

2019-06-12  本文已影响0人  左右飘忽

一、在窗口一创建委托
public delegate void ShowMessageService(string msg);
二、调用
ShowMessageService sms = new ShowMessageService(formLBS.UpdateLabel);//定义委托对象,指向子窗口的UpdateLabel方法。
this.BeginInvoke(sms, "实时传递的消息"); //执行的是子窗口的Up
三、在窗口二定义响应委托的方法
public async void UpdateLabel(string msg)
{
// await Task.Delay(2000);
if (this.tbLCStart.Focused)
{ this.tbLCStart.Text = msg; }
if(this.tbLCEnd.Focused)
{
this.tbLCEnd.Text = msg;
}
if (this.tXStart.Focused)
{
this.tXStart.Text = msg;
}
if (this.tXEnd.Focused)
{
this.tXEnd.Text = msg;
}

    }

四,效果如下


image.png
上一篇 下一篇

猜你喜欢

热点阅读