public static void Write(string strInfo) { if (TextBoxLog == null) { return; } if (string.IsNullOrEmpty(strInfo)) { return; } //if (InfoDockContainerItem == null) // return; //InfoDockContainerItem.Selected = true; string strNewLine = ""; if (TextBoxLog.Text.Length > 0) { strNewLine = Environment.NewLine; } if (TextBoxLog.InvokeRequired) { AppendMessage appendMsg = delegate(string msg) { Write(msg); }; TextBoxLog.Invoke(appendMsg, new object[] { strInfo }); } else { try { string strPrefix = ""; if (OutputTime) { strPrefix = DateTime.Now.ToString("HH:mm:ss") + " "; } XStrings xstrsInfoLines = strInfo.Split('\n'); for (int i = 1; i < xstrsInfoLines.Count; i++) { xstrsInfoLines[i] = string.Empty.PadLeft(strPrefix.Length) + xstrsInfoLines[i]; } TextBoxLog.AppendText(strNewLine + strPrefix + xstrsInfoLines.ToLongString(false)); TextBoxLog.ScrollToCaret(); } catch (Exception) { // 当窗体先退出时将发生此异常 XLog.TextBoxLog = null; return; } } }
public MainForm() { InitializeComponent(); appendMessage = new AppendMessage(AppendLabel); ButtonComp(); BindRegionCbox(); BindDrivesCbox(); rbnShidaidianzi.Enabled = true; // bgwLoading.RunWorkerAsync(); }
private void btnStart_Click(object sender, EventArgs e) { string path = txtPath.Text; if (string.IsNullOrEmpty(path)) { MessageBox.Show("请输入路径!"); return; } appendMessage = new AppendMessage(AppendLabel); LogInfo li = new LogInfo(); li.path = txtPath.Text; DataRowView dr = cbxRegionCode.SelectedItem as DataRowView; li.regioncode = dr["code"].ToString(); bgwImport.RunWorkerAsync(li); }