我的代码如下void load()
{
Thread receiveThread = new Thread(ReceiveMessage);
receiveThread.Start();
}
private void ReceiveMessage()
{
while (true)
{
try
{
byte[] receiveBytes = receiveUpdClient.Receive(ref remoteIpEndPoint);
string get = Encoding.Unicode.GetString(receiveBytes);
if (get == "head")
{
PictureBox p = new PictureBox();
p.Image = Properties.Resources.head;
p.SizeMode = PictureBoxSizeMode.StretchImage;
panel1.Controls.Add(p);//这里提示标题错误
}
}
catch(Exception e)
{
string x = e.Message;
break;
}
}
}
求问我该怎么改?谢谢!
{
Thread receiveThread = new Thread(ReceiveMessage);
receiveThread.Start();
}
private void ReceiveMessage()
{
while (true)
{
try
{
byte[] receiveBytes = receiveUpdClient.Receive(ref remoteIpEndPoint);
string get = Encoding.Unicode.GetString(receiveBytes);
if (get == "head")
{
PictureBox p = new PictureBox();
p.Image = Properties.Resources.head;
p.SizeMode = PictureBoxSizeMode.StretchImage;
panel1.Controls.Add(p);//这里提示标题错误
}
}
catch(Exception e)
{
string x = e.Message;
break;
}
}
}
求问我该怎么改?谢谢!
panel1.Controls.Add(p);}); public delegate void DummyDelegate();这样试试
this.Invoke((DummyDelegate)delegate() {PictureBox p = new PictureBox();
p.Image = Properties.Resources.head;
p.SizeMode = PictureBoxSizeMode.StretchImage;
panel1.Controls.Add(p);<span style="color: #FF0000;">
});
public delegate void DummyDelegate();