2014-02-17 72 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