Public Class RuningLog 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 = 1 Then Dim nc As RichTextBox = c '获取富文本字符串末端位置 Dim index As Integer = nc.TextLength Dim strtxt = AddTimeStamps(config.logstr) '设置光标位置 nc.SelectionStart = index '添加文本 nc.AppendText(strtxt) '设置选择区域 nc.Select(index, strtxt.Length) '设置选择区域颜色 nc.SelectionColor = config.logstrColor '设置选择区域字体 nc.SelectionFont = config.logstrFont '取消选中区域 nc.DeselectAll() Else c.Text = AddTimeStamps(config.logstr) c.ForeColor = config.logstrColor c.Font = config.logstrFont 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") & " " & str & vbCrLf 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 ''' ''' 文本、颜色、Font ''' ''' Sub New(ParamArray args() As Object) If args.Length > 0 Then logstr = 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 Else logstrColor = Color.Black End If Else logstr = "输空文本" logstrColor = Color.Black logstrFont = New Font("宋体", 12) End If End Sub End Class