[C #] how to display the contents of the edit control in the sub-thread

        Since the main function, which is to display the contents of the edit box is not a problem, but in the sub-thread, the object can not edit box class custom button functions, it is not directly displayed, on the one hand you can control class object definitions for static static form, but this is like building a house, you should first drawing paper, a house under construction, while the control class object definitions for static static form like directly to open space directly to the house and left there, while ignoring the first draw the process of drawing. While running show is also no problem, but it seems very reasonable, so here presents a delegate (delegate) mode, showing the contents of the edit box in the sub-thread.

First, in Test () function, a delegate Method, () function is passed the parameter string type aaa

string aaa = "bbbbbbbbbbbbbb";
delegate void add(string text);//委托     
public void Test()
{

BeginInvoke(new add(Method), aaa);

}
public void Method(string input)
{
//编辑框对象 textBoxShow
 textBoxShow.Text = input;      
   
}

Second, the function buttons open thread, the edit box displays the information in the sub-thread

private void OpenImage_Click(object sender, EventArgs e)
 {
 
     Thread thread = new Thread(new ThreadStart(Test));
     thread.Start();
     
 }

Published 74 original articles · won praise 24 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43197380/article/details/103935561