美文网首页
C# 窗口之间传递数据实时显示

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

作者: 左右飘忽 | 来源:发表于2019-06-12 17:37 被阅读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

相关文章

网友评论

      本文标题:C# 窗口之间传递数据实时显示

      本文链接:https://www.haomeiwen.com/subject/zufrfctx.html