C # static function, how to operate the controls in the Form?

1.第一个问题,关于,回调函数是否必须为静态函数或者全局函数?

2.第二个问题,静态函数,如何操作Form中的控件?
public static Form1 form1;

public Form1()
{
   InitializeComponent();

   form1 = this;
}

state.workSocket = handler;
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);

public static void ReadCallback(IAsyncResult ar)
{
 Form1.form1.textBoxReceive.AppendText(strmsgtemp);
}

3. The third question: the non-threaded create a control, not access

//非创建控件线程,无法访问
//richTextBox1.AppendText(Encoding.ASCII.GetString(data, 0, recvlength));

delegate void richtexttip();
richtexttip richtext3 = delegate()
{
  richTextBox1.AppendText("client:"+Encoding.Unicode.GetString(data, 0, recvlength) + "\r\n");
};
richTextBox1.Invoke(richtext3);



Published 161 original articles · won praise 17 · views 730 000 +

Guess you like

Origin blog.csdn.net/nanfeiyannan/article/details/42076271