diff --git a/EX/ExProgram.xaml b/EX/ExProgram.xaml index 8075820..0cfde24 100644 --- a/EX/ExProgram.xaml +++ b/EX/ExProgram.xaml @@ -5,12 +5,12 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:formula_manage.EX" mc:Ignorable="d" - Title="ExProgram" Height="450" Width="800"> + Title="ExProgram" Height="450" Width="800" Background="#FFE0E0E0"> - + diff --git a/EX/ExProgram.xaml.cs b/EX/ExProgram.xaml.cs index 4696f45..e7e1fcb 100644 --- a/EX/ExProgram.xaml.cs +++ b/EX/ExProgram.xaml.cs @@ -1,4 +1,5 @@ -using System; +using formula_manage.UserClass; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -22,6 +23,7 @@ namespace formula_manage.EX public ExProgram() { InitializeComponent(); + Log.SetTextControl(textLog); } } } diff --git a/UserClass/Log.cs b/UserClass/Log.cs new file mode 100644 index 0000000..d37577c --- /dev/null +++ b/UserClass/Log.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Documents; +using System.Windows.Controls; +using System.Windows.Media; + +namespace formula_manage.UserClass +{ + public static class Log + { + private const int MaxCount = 1000; + private static int Count = 0; + private static RichTextBox textControl; + private static InlineCollection inlines; + + //设置主控件 + public static void SetTextControl(RichTextBox _textBox) + { + textControl = _textBox; + Paragraph graph = new Paragraph(); + inlines = graph.Inlines; + textControl.Document.Blocks.Add(graph); + } + + //输出黑色消息 + public static void Info(string format, params object[] args) + { + AppendText(Brushes.Black, format, args); + } + + //输出绿色消息 + public static void Suc(string format, params object[] args) + { + AppendText(Brushes.DarkGreen, format, args); + } + + //输出黄色消息 + public static void Warning(string format, params object[] args) + { + AppendText(Brushes.DarkOrange, format, args); + } + + //输出红色消息 + public static void Error(string format, params object[] args) + { + AppendText(Brushes.Red, format, args); + } + + //清除日志 + public static void Clear() + { + Count = 0; + inlines.Clear(); + textControl.ScrollToEnd(); + } + + private static void AppendText(Brush color, string format, params object[] args) + { + textControl.BeginChange(); + StringBuilder builder = new StringBuilder(); + builder.Append("["); + builder.Append(Count++); + builder.Append("] : "); + builder.Append(string.Format(format, (object[])args)); + builder.Append("\n"); + string str = builder.ToString(); + inlines.Add(new Run(str) { Foreground = color }); + if (inlines.Count > MaxCount) + { + inlines.Remove(inlines.FirstInline); + } + textControl.ScrollToEnd(); + textControl.EndChange(); + } + + } +} diff --git a/formula_manage.csproj b/formula_manage.csproj index 8b0fef6..545622a 100644 --- a/formula_manage.csproj +++ b/formula_manage.csproj @@ -261,6 +261,7 @@ +