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 '输出日志到控件 ''' ''' ''输出日志到控件 ''' ''' 控件 ''' 日志 ''' 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 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() ''' ''' 文本、颜色、Font ''' ''' '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 Sub New(ParamArray args() As Object) logstr = RuningLog.AddTimeStamps(args(0).ToString) logstrColor = args(1) logstrFont = New Font("宋体", CInt(args(2))) End Sub End Class