跨线程给窗体的控件赋值

1、创建委托

  private delegate void AddImageToPicturboxCallBack(string imageAddress);

2、 创建委托的方法

 private  void AddImageToPicturbox(string imageAddree)
        {
            if (pictureBox1.InvokeRequired)
            {
                AddImageToPicturboxCallBack d1 = new AddImageToPicturboxCallBack(AddImageToPicturbox);
                this.Invoke(d1, new object[] { imageAddree});
            }
            else
            {
                pictureBox1.Image = Image.FromFile(imageAddree, false);
            }
            
        }

3、直接调用方法即可  

   AddImageToPicturbox(pi.Address);

 

posted @ 2019-04-29 11:09  紫藤球球  阅读(276)  评论(0编辑  收藏  举报