C# 静态函数调用窗体控件

回调函数方法是静态函数,需要调用窗体控件,赋值或取值。

定义 public static Form1 mainFrm;   mainFrm = this;

 public partial class Form1 : Form
{
public static Form1 mainFrm;
public Form1()
{
mainFrm = this;
InitializeComponent();
}
  public static void WaitCallBackReceiveConnectedInfo(string connecetedIp,string leaveIp)
{
Form1.mainFrm.rtxtMsg.BeginInvoke(new InvokeDelegate(InvokeMethod), new object[] { connecetedIp, leaveIp }); }
public delegate void InvokeDelegate(string connecetedIp, string leaveIp);
public static void InvokeMethod(string connecetedIp, string leaveIp)
{
if (connecetedIp != "")
{
Form1.mainFrm.cmbConnectedIP.Items.Add(connecetedIp);
Form1.mainFrm.rtxtMsg.AppendText(connecetedIp+" 连接上来\r\n");
Form1.mainFrm.cmbConnectedIP.SelectedIndex = ;
} if (leaveIp != "")
{
Form1.mainFrm.cmbConnectedIP.Items.Remove(leaveIp);
Form1.mainFrm.rtxtMsg.AppendText(leaveIp + " 离开\r\n");
} }
上一篇:WPS之word文档处理(持续更新)


下一篇:debian/deepin 15.3安装jdk 1.7 (或jdk 7),配置默认环境