Commit 991bb7e0 LN

日志修改

1 个父辈 954d374f
...@@ -145,6 +145,7 @@ ...@@ -145,6 +145,7 @@
this.logBox.Size = new System.Drawing.Size(860, 350); this.logBox.Size = new System.Drawing.Size(860, 350);
this.logBox.TabIndex = 106; this.logBox.TabIndex = 106;
this.logBox.Text = ""; this.logBox.Text = "";
this.logBox.VisibleChanged += new System.EventHandler(this.logBox_VisibleChanged);
// //
// groupBox3 // groupBox3
// //
......
...@@ -806,5 +806,13 @@ namespace OnlineStore.AssemblyLine ...@@ -806,5 +806,13 @@ namespace OnlineStore.AssemblyLine
LogUtil.info("手动更新托盘信息:" + info.ToStr()); LogUtil.info("手动更新托盘信息:" + info.ToStr());
} }
} }
private void logBox_VisibleChanged(object sender, EventArgs e)
{
if (logBox.Visible)
{
LogUtil.UpdateLogbox();
}
}
} }
} }
...@@ -100,6 +100,7 @@ namespace OnlineStore.Common ...@@ -100,6 +100,7 @@ namespace OnlineStore.Common
} }
} }
private static List<string> logList = new List<string>(); private static List<string> logList = new List<string>();
public static string LastText = "";
private static void ShowLogPro(string msg, Color color) private static void ShowLogPro(string msg, Color color)
{ {
try try
...@@ -123,25 +124,45 @@ namespace OnlineStore.Common ...@@ -123,25 +124,45 @@ namespace OnlineStore.Common
{ {
return; return;
} }
LastText = text;
if (logBox.Visible)
{
logBox.Text = text; logBox.Text = text;
// logBox.Focus(); //使文本框获取焦点 // logBox.Focus(); //使文本框获取焦点
logBox.AppendText(now.ToLongTimeString() + " " + msg + Environment.NewLine); //增加文本 logBox.AppendText(now.ToLongTimeString() + " " + msg + Environment.NewLine); //增加文本
TimeSpan span = DateTime.Now - lastTime;
if (span.TotalSeconds > 10)
{
lastTime = DateTime.Now;
logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾 logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾
logBox.ScrollToCaret(); //滚动到控件光标处 logBox.ScrollToCaret(); //滚动到控件光标处
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
LOGGER.Error("出错:" + ex.ToString()); LOGGER.Error("出错:" + ex.ToString());
} }
} }
private static DateTime lastTime = DateTime.Now;
public static void UpdateLogbox()
{
if (logBox != null && logBox.Visible)
{
logBox.Text = LastText;
logBox.Select(logBox.Text.Length, 0); //设置光标的位置到文本尾
logBox.ScrollToCaret(); //滚动到控件光标处
}
}
public static void ClearLog() public static void ClearLog()
{ {
if (logBox != null) if (logBox != null)
{ {
LastText = "";
logList.Clear(); logList.Clear();
logBox.Text = ""; logBox.Text = "";
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!