Change color in output to TextBox depending on error or not

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
twp111
Posts: 4
Joined: Tue Mar 25, 2014 2:51 am

Change color in output to TextBox depending on error or not

Post by twp111 » Thu Apr 03, 2014 4:37 am

Hi,
I'm new to GUI-powershell scripts. Have made a GUI in Primal Forms for an AD-script I use to handle group-members. I log what happens to a TextBox ($LogBox). Now I would like to change the color of the log dependin if I get an error or not.

Have tried to search this forum and google it but cant find anything that would help me.

I can change color of everything in the textbox with $LogBox.forecolor = "red" but that is not what i want. I just want to change specific lines in the textbox. Not everything!

ex:
PowerShell Code
Double-click the code block to select all.
$LogBox.AppendText("***Error! Conputer: $Computer could not be found i AD"+[char]13+[char]10)
Can anyone please help me with an example of how to make the line above be written in RED?

User avatar
boyddt_co
Posts: 75
Joined: Mon Dec 17, 2007 5:50 am

Re: Change color in output to TextBox depending on error or

Post by boyddt_co » Thu Apr 03, 2014 2:53 pm

I'm running into the same issue and it appears that the text box sees all text as the same, more or less like Notepad. I'm still sorting things out but it looks like I'll be creating a large number of smaller text boxes so that I can manipulate the text individually based on current status.

User avatar
twp111
Posts: 4
Joined: Tue Mar 25, 2014 2:51 am

Re: Change color in output to TextBox depending on error or

Post by twp111 » Thu Apr 03, 2014 3:05 pm

boyddt_co wrote:I'm running into the same issue and it appears that the text box sees all text as the same, more or less like Notepad. I'm still sorting things out but it looks like I'll be creating a large number of smaller text boxes so that I can manipulate the text individually based on current status.
Hm, that doesn't sound good. Im pretty shore that I have seen it done but can't find the scrip. Mabe it wasn't primal forms. How about I you try the richtextbox or whatever it's name is? There have to be a solution to this! :)

Locked