![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
private delegate void WriteToRbxMsgHandle( string msg, bool isError);
private void WriteToRbxMsg( string msg, bool isError)
{
if ( ! this .rbxWorkingMsg.InvokeRequired)
{
WriteToRbxMsgDMethod(msg, isError);
}
else
{
this .rbxWorkingMsg.Invoke( new WriteToRbxMsgHandle(WriteToRbxMsgDMethod), msg, isError);
}
}
private void WriteToRbxMsgDMethod( string msg, bool isError)
{
if (isError)
{
this .rbxWorkingMsg.SelectionColor = Color.Red;
}
else
{
this .rbxWorkingMsg.SelectionColor = Color.Black;
}
this .rbxWorkingMsg.SelectedText = msg + " \n " ;
this .rbxWorkingMsg.Focus();
this .rbxWorkingMsg.Select( this .rbxWorkingMsg.Text.Length, 0 );
}
简单的:需要提前声明一个委托:PortNumberReadyEventHandler
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
void
tcpReceiver_PortNumberReady(
object
Sender, PortNumberReadyEventArgs PNR)
{
if ( this .InvokeRequired)
{
PortNumberReadyEventHandler del = delegate ( object sender, PortNumberReadyEventArgs pnr)
{
this .Text += pnr.PortNum.ToString();
};
this .Invoke(del , this ,PNR);
}
}
{
if ( this .InvokeRequired)
{
PortNumberReadyEventHandler del = delegate ( object sender, PortNumberReadyEventArgs pnr)
{
this .Text += pnr.PortNum.ToString();
};
this .Invoke(del , this ,PNR);
}
}