Change the font colour output that display in System.Windows.Forms.RichTextBox

Hi

I am trying to change the font colour output that display in System.Windows.Forms.RichTextBox
Below is the code

function pingInfo {
$outputBox.Clear()
$computers = $InputBox.lines.Split(“n") </code> <code>foreach ($computer in $computers) { </code> <code>if (Test-Connection $computer -Count 1 -Quiet) {</code> <code>$serveronline = "$computer is online"</code> <code>$outputBox.Appendtext("{0}n” -f $serveronline)
}
else {
$serveroffline = “$computer is offline”
$outputBox.Appendtext("{0}`n" -f $serveroffline)
}
}
}

For example I want “computer is online” in green and “computer is offline” in red

Code updated:

function pingInfo { 
$outputBox.Clear() 
$computers = $InputBox.lines.Split("`n") 
foreach ($computer in $computers) { 
if (Test-Connection $computer -Count 1 -Quiet) {
$serveronline = "$computer is online"
$outputBox.Appendtext("{0}`n" -f $serveronline)
}
else {
$serveroffline = "$computer is offline"
$outputBox.Appendtext("{0}`n" -f $serveroffline)
} 
} 
}

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.richtextbox.forecolor?view=netcore-3.1

 

Resolved.

function pingInfo { 
$outputBox.Clear() 

$computers = $InputBox.lines.Split("`n") 

foreach ($computer in $computers) { 

    if (Test-Connection $computer -Count 1 -Quiet) {

        $outputBox.Font = "Calibri,11,style=Bold"

        $outputBox.SelectionColor = "#007F00"

        $outputBox.AppendText("$computer is Online`n")

    }

    else {

        $outputBox.Font = "Calibri,11,style=Bold"

        $outputBox.SelectionColor = "#FF0000"

        $outputBox.AppendText("$computer is Offline`n")

    }  

} 

}