日期:2014-05-18  浏览次数:20843 次

C#委托:如何在主窗口调用的线程里写主窗口的控件?
结构简单如下:
C# code

namespace AccessTest
{
    public  partial class Form1 : Form
    {
        //public delegate void setCap(string caption);
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ThreadStart st = new ThreadStart(new DBio().Work);
            Thread t = new Thread(st);
            t.Start();
        }
        public void setLog(string cap)
        {
            this.Text = cap;
        }
    }
    public class DBio
    {
        public void Work()
        {
            改写Form1.Text,这里应该这么写呢?
        }
    }
}




------解决方案--------------------
C# code
 Form prform;//主窗体

 private void FormShow() 
        {
            switch (re_message)
            {
                ............
            }
        }

 MethodInvoker mi = new MethodInvoker(FormShow);
                    prform.BeginInvoke(mi);