Reputation: 117
I have created a method where in the code you can write WritetoConsole(SomeString, LogType)
but when the LogType is activated, (A different color per type of log), it changes the entire color of the richtextbox, not the actual line that was entered.
It's supposed to be a custom console in a WinForm Application. So Basically Whatever is inputed into Message
is what should be written to the console, dependingon LogitType. But I don't want it to change the entire RichTextBox's text color. I just want the specific line that's being entered
Dim NewLine As String = (Chr(13))
Dim LogType As LogerType
''' <summary>
''' Writes a Message to the Homework Helper Console
''' </summary>
''' <param name="Message">The Message to Display to Console</param>
''' <param name="LogitType">The Type of Message to Display to Console</param>
''' <remarks></remarks>
Public Sub WritetoConsole(Message As String, LogitType As Color)
LogerType.Normal = Color.White
LogerType.Warning = Color.Yellow
LogerType.ErrorMessage = Color.Maroon
LogerType.Homework = Color.Green
LogerType.Project = Color.Red
LogerType.Test = Color.RosyBrown
If Message = Nothing Then
rtbInput.AppendText(Errors(3))
Else
rtbInput.AppendText(NewLine & Message)
End If
If LogitType = LogerType.Normal Then
rtbInput.ForeColor = LogerType.Normal
ElseIf LogitType = LogerType.Warning Then
rtbInput.ForeColor = LogerType.Warning
ElseIf LogitType = LogerType.ErrorMessage Then
rtbInput.ForeColor = LogerType.ErrorMessage
ElseIf LogitType = LogerType.Homework Then
rtbInput.ForeColor = LogerType.Homework
ElseIf LogitType = LogerType.Project Then
rtbInput.ForeColor = LogerType.Project
ElseIf LogitType = LogerType.Test Then
rtbInput.ForeColor = LogerType.Test
ElseIf LogitType = Nothing Then
WritetoConsole((Errors(3)), LogerType.ErrorMessage)
Else
MsgBox(Errors(4))
End If
End Sub
Upvotes: 0
Views: 609
Reputation: 7204
You have to use rtbInput.SelectionColor
not rtbInput.ForeColor
. So:
Public Sub WritetoConsole(Message As String, LogitType As Color)
LogerType.Normal = Color.White
LogerType.Warning = Color.Yellow
LogerType.ErrorMessage = Color.Maroon
LogerType.Homework = Color.Green
LogerType.Project = Color.Red
LogerType.Test = Color.RosyBrown
rtbInput.Select(rtbInput.TextLength, 0)
If LogitType = LogerType.Normal Then
rtbInput.SelectionColor= LogerType.Normal
ElseIf LogitType = LogerType.Warning Then
rtbInput.SelectionColor= LogerType.Warning
ElseIf LogitType = LogerType.ErrorMessage Then
rtbInput.SelectionColor= LogerType.ErrorMessage
ElseIf LogitType = LogerType.Homework Then
rtbInput.SelectionColor= LogerType.Homework
ElseIf LogitType = LogerType.Project Then
rtbInput.SelectionColor= LogerType.Project
ElseIf LogitType = LogerType.Test Then
rtbInput.SelectionColor= LogerType.Test
ElseIf LogitType = Nothing Then
WritetoConsole((Errors(3)), LogerType.ErrorMessage)
Else
MsgBox(Errors(4))
End If
If Message = Nothing Then
rtbInput.AppendText(Errors(3))
Else
rtbInput.AppendText(NewLine & Message)
End If
End Sub
valter
Upvotes: 0