界面布局设置

This commit is contained in:
zhengxuan.zhang
2023-10-08 14:12:16 +08:00
parent 8bef038966
commit 790f217e62
20 changed files with 9808 additions and 25 deletions
+129
View File
@@ -0,0 +1,129 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HexcalMC.Base
{
public class DebugDfn
{
public static string strDebugFile = Application.StartupPath + "\\File\\Debug.txt";
public static string strDebugSavePath = Application.StartupPath + "\\File\\DebugFiles";
public static string strDebugFileTemp = Application.StartupPath + "\\File\\DebugTemp.txt"; //临时存储,用于菜单查看
static string strStartTime = ""; //程序启动时间
static string strEndTime = ""; //程序关闭时间
public static RichTextBox textBox_Msg;
//=================================================================
public static void StartDebugObj()
{
System.IO.TextWriter log = new System.IO.StreamWriter(DebugDfn.strDebugFile);
TextWriterTraceListener logger = new TextWriterTraceListener(log);
Trace.Listeners.Add(logger);
strStartTime = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
}
public static void SaveDebugFile()
{
AddLog("软件关闭!");
strEndTime = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss");
string CopyFileName = strDebugSavePath + "\\DebugFiles\\" + "Debug(" + strStartTime + " To " +
strEndTime + ")" + ".txt";
if (File.Exists(strDebugFile))
File.Copy(strDebugFile, CopyFileName, true);
}
//=================================================================
#region
public static void AddLog(string str)
{
MyBase.TraceWriteLine(str);
}
public static void AddLogText(string str, Color m_Color = new Color())
{
MyBase.TraceWriteLine(str);
try
{
textBox_Msg.BeginInvoke((EventHandler)delegate
{
Color SetColor = Color.White;
if (m_Color == new Color())
{
if (str.ToUpper().Contains("ERROR") || str.ToUpper().Contains("错误") ||
str.ToUpper().Contains("出错") || str.ToUpper().Contains("EXCEPTION") ||
str.ToUpper().Contains("异常") || str.ToUpper().Contains("失败"))
{
SetColor = Color.Red;
}
else if (str.ToUpper().Contains("WARNING") || str.ToUpper().Contains("警告"))
{
SetColor = Color.DarkOrange;
}
}
else
{
SetColor = m_Color;
}
string strText = DateTime.Now.ToString("HH:mm:ss.ff") + "--" + str + Environment.NewLine;
textBox_Msg.SelectionStart = textBox_Msg.TextLength;
if (string.IsNullOrEmpty(str))
SetText(textBox_Msg, str, SetColor, false, 16);
else
SetText(textBox_Msg, strText, SetColor, false, 16);
if (textBox_Msg.Lines.Length > 800)
{
textBox_Msg.Select(0, textBox_Msg.TextLength / 2);
textBox_Msg.Cut();
}
textBox_Msg.ScrollToCaret();
});
}
catch
{
}
}
public static void SetText(RichTextBox m_RichTextBox, string strText, Color m_Color, bool bBold = false,
float Size = 16)
{
m_RichTextBox.Invoke(((EventHandler)delegate
{
SetFont(m_RichTextBox, m_Color, bBold, Size);
m_RichTextBox.SelectedText = strText;
}));
}
public static void SetFont(RichTextBox m_RichTextBox, Color m_Color, bool bBold = false, float Size = 16)
{
m_RichTextBox.SelectionColor = m_Color;
if (bBold)
m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
else
m_RichTextBox.SelectionFont = new System.Drawing.Font("Segoe UI", Size,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));
}
public static void SetErrorColor(Color InColor)
{
if (textBox_Msg != null)
{
textBox_Msg.BeginInvoke((EventHandler)delegate { textBox_Msg.BackColor = InColor; });
}
}
#endregion
}
}