在一个窗体中创建一个线程,线程中的方法需要修改这个窗体中控件的属性,比如显隐等,可是调用时说不可修改创建线程窗体的控件,请高人指教如何实现

解决方案 »

  1.   

    用委托,invoke,我刚碰到过
    我还有个问题呢,有时间帮我看下http://topic.csdn.net/u/20110823/15/6e02718d-fedb-475e-b142-132dcb9634e4.html?98078
      

  2.   

    例:
    private delegate void WriteTxtDelegate(TextBox tb,string p_info);
     private void WriteTextBox(TextBox tb,string p_info)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new WriteTxtDelegate(WriteTextBox), new object[] { tb, p_info });
                }
                else
                {
                    lock (sTxtBoxObj)
                    {
                        try
                        {
                            int intLine = System.Text.RegularExpressions.Regex.Matches(tb.Text, "\r\n").Count;
                            if (intLine > 200)
                                tb.Text = DateTime.Now.ToString() + ":" + p_info + "\r\n";
                            else
                                tb.Text += DateTime.Now.ToString() + ":" + p_info + "\r\n";                        tb.Select(tb.TextLength, 0);
                            tb.ScrollToCaret();
                        }
                        catch { }
                    }
                }        }还有,你给的分太少了
      

  3.   


    private void setTextBox1Visible_Click(object sender, EventArgs e)
    {
        Action func = () =>
        {
            this.textBox1.Visible = true;
        };
        if (this.textBox1.InvokeRequired)
        {
            this.textBox1.Invoke(func);
        }
        else
        {
            func();
        }

      

  4.   


    要学习看我这个
    http://topic.csdn.net/u/20110823/15/6e02718d-fedb-475e-b142-132dcb9634e4.html