您现在的位置:首页 >> 软件开发 >> 内容

在线程中更改主线程UI控件的方法-C#

时间:2023-12-12 23:13:44 点击:

  核心提示:方法1:使用委托方法//跨线程访问UI控件if (this.InvokeRequired){ this.Invoke(new MethodInvoker(delegate { dataGridView...

方法1:使用委托方法


//跨线程访问UI控件
 if (this.InvokeRequired)
 {
      this.Invoke(new MethodInvoker(delegate
       {


         dataGridView1.DataSource = tblDatas;


        }));
 }//跨线程访问UI控件


方法2:在程序中加入下面这一句


 //允许操作其它线程创建的控件
 Control.CheckForIllegalCrossThreadCalls = false;


 

作者:站长 来源:网络
相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 陈工笔记(www.dui580.com) © 2024 版权所有 All Rights Reserved.
  • 站长:陈工 微信号:chengongbiji QQ:24498854
  • Powered by 陈工