Files
Desktop_485BurningTool/Log/RuningLog.vb
2025-12-11 10:09:40 +08:00

120 lines
3.8 KiB
VB.net
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Public Class RuningLog
Public Shared level As Integer = 1 '日志级别 0不输出日志 1输出日志2输出基础日志和错误信息
Delegate Function Deleg_OutputLogsToTheControl(c As Control config As RuningLogConfig, Controltype As Integer) As Boolean
'输出日志到控件
''' <summary>
''' ''输出日志到控件
''' </summary>
''' <param name="c">控件 </param>
''' <param name="config">日志</param>
''' <returns></returns>
Public Shared Function OutputLogsToTheControl(c As Control config As RuningLogConfig, Controltype As Integer) As Boolean
Try
If c.InvokeRequired Then
Dim dev As New Deleg_OutputLogsToTheControl(AddressOf OutputLogsToTheControl)
c.Invoke(dev, New Object() {c, config, Controltype})
Else
If Controltype >= level Then
Dim nc As RichTextBox = c
'获取富文本字符串末端位置
Dim index As Integer = nc.TextLength
If (Not IsNothing(config.strdata)) AndAlso config.strdata.Length > 0 Then
config.logstr = config.logstr & DataProcessing.ByteToString2(config.strdata)
End If
Dim strtxt = config.logstr & vbCrLf
'设置光标位置
nc.SelectionStart = index
'添加文本
nc.AppendText(strtxt)
'设置选择区域
nc.Select(index, strtxt.Length)
'设置选择区域颜色
nc.SelectionColor = config.logstrColor
'设置选择区域字体
nc.SelectionFont = config.logstrFont
'取消选中区域
nc.DeselectAll()
End If
End If
Catch ex As Exception
End Try
End Function
'字符串附加时间戳
Public Shared Function AddTimeStamps(str As String) As String
Return Now.ToString("yyyy-MM-dd HH:mm:ss:fff") & " " & str
End Function
'设置显示等级
Public Shared Sub SetLevel(level As Integer)
RuningLog.level = level
End Sub
End Class
Public Class RuningLogConfig
'日志信息
Public logstr As String
'日志信息颜色
Public logstrColor As Color
'日志信息字体
Public logstrFont As Font
'日志信息字体大小
'Public logstrFontSize As Integer
''日志信息字体粗细
'Public logstrFontBold As Boolean
''日志信息字体斜体
'Public logstrFontItalic As Boolean
''日志信息字体下划线
'Public logstrFontUnderline As Boolean
''日志信息字体删除线
'Public logstrFontStrikeout As Boolean
''日志信息字体对齐方式
'Public logstrFontAlign As StringAlignment
'日志信息字体背景色
Public logstrFontBackColor As Color
Public strdata As Byte()
''' <summary>
''' 文本、颜色、Font
''' </summary>
''' <param name="args"></param>
Sub New(ParamArray args() As Object)
If args.Length > 0 Then
logstr = RuningLog.AddTimeStamps(args(0).ToString)
If args.Length > 1 Then
logstrColor = args(1)
If args.Length > 2 Then
logstrFont = args(2)
Else
logstrFont = New Font("宋体", 8)
End If
If args.Length > 3 Then
strdata = args(3)
Else
strdata = Nothing
End If
Else
logstrColor = Color.Black
End If
Else
logstr = "输空文本"
logstrColor = Color.Black
logstrFont = New Font("宋体", 12)
End If
End Sub
End Class