public void AddtoBox(Color fontcolor, string strcommand) { if (CommandLineBox.InvokeRequired)//不是同一线程调用,调用控件的委托 { AddBoxCallback d = new AddBoxCallback(AddtoBox); this.Invoke(d, new object[] { fontcolor, strcommand }); } else//同一线程,直接操作 { if (CommandLineBox.TextLength > 150000) { CommandLineBox.Select(0, CommandLineBox.TextLength / 3); CommandLineBox.Cut(); } CommandLineBox.SelectionColor = fontcolor; CommandLineBox.AppendText(strcommand); CommandLineBox.ScrollToCaret(); CommandLineBox.SelectionColor = Color.Black; strcommand = strcommand.Replace(@"/>", ""); MainForm.pMainForm.mapdoc.WriteNetLog(strcommand); if (NetLogFile.logfile.ws == null)//还未创建文件 { NetLogFile.OpenFile(MainForm.pMainForm.RecordInfo); } NetLogFile.writeLine("\r\n" + strcommand); if (NetLogFile.length >= 600 * 1024)//不允许大于600K { NetLogFile.close(); } if (MainForm.pMainForm.AutoConnectWin.Visible) { MainForm.pMainForm.AutoConnectWin.AddToBox(strcommand); } } }
public void AddToBox(string s) { if (MsgBox.InvokeRequired) { AddBoxCallback d = new AddBoxCallback(AddToBox); this.Invoke(d, new object[] { s }); } else { MsgBox.AppendText(s); } }