2014-02-17 75 views
0

在RichTextBox的特定顏色我已經創建在代碼中,你可以寫WritetoConsole(SomeString, LogType)但是當日志類型被激活,(每個類型的日誌,不同的顏色),它改變了整個色的方法richtextbox,而不是輸入的實際行。如何更改線路,以基於子

它應該是在WinForm應用程序自定義控制檯。所以基本上無論輸入到Message什麼都應該寫入控制檯,取決於LogitType。但我不希望它改變整個RichTextBox的文本顏色。我只是想這就是BEING進入

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 
+0

你你的寫作沒有寫入控制檯一個RichTextBox,非常不同。 – Codexer

+0

另外你已經聲明一個變量logtype爲logertype,但不使用它。我會把它們放在一個枚舉中並以這種方式使用它們。 – Codexer

+0

@MrCoDeXeR rtbInput.AppendText(換行和消息)添加到RichTextBox中,使它看起來像一個控制檯...使子過程WritetoConsole(消息作爲字符串,LogitType顏色)使其能夠工作就像是使用WritetoConsole控制檯(消息,LogitType) – user2678408

回答

0

你必須使用rtbInput.SelectionColorrtbInput.ForeColor具體的線路。所以:

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 

瓦爾特

+0

這仍然將在框中選擇不正是他需要 – Codexer

+0

好吧,他再次呼籲這個時候會選擇裏面的文本的整個長度的所有文字,你有沒有測試它,我沒有和不工作,請務必在發佈解決方案之前進行測試 – Codexer

+0

看看屏幕截圖,它爲自己說明了好友。我寫了一個功能,這個功能好上百倍。其實就是兩天前幫助一個人。 – Codexer