I am trying to add lines to a richtextbox using .appendtext. Things work fine with the first line, however once I add an new line the whole box changes to the new color.
Below is the code that runs on a submit button. The colors are choosen from a set of radio buttons ($global:textcolor) and there is a text box to type in some text ($mainTextbox1)
$mainButtonSubmit_Click = {
$mainRichTextbox1.ForeColor = [Drawing.Color]::$($global:textcolor)
$mainRichTextbox1.AppendText("$($mainTextbox1.text)`n")
}
Any assistance would be appreciated
Adding new lines to RichTextbox with different colors
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.
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.
Re: Adding new lines to RichTextbox with different colors
Thanks for the advice. I am new to using powershell GUIs can you provide a code snippet or article to help.
Re: Adding new lines to RichTextbox with different colors
Here is an old demo of how to add color.
- Attachments
-
- Demo-RTFColors.psf
- (18.94 KiB) Downloaded 1691 times
Re: Adding new lines to RichTextbox with different colors
Thanks for the response. I tried that last night but it appears that .SelectionColor is no longer a command. i get the below error message. Am I doing something wrong?
The property 'SelectionColor' cannot be found on this object. Verify that the property exists and can be set.
MainForm.psf (44, 2): ERROR: At Line: 44 char: 2
ERROR: + $mainRichTextbox1.SelectionColor='red'
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : PropertyAssignmentException
ERROR:
Heres the updated snippet.
$mainButtonSubmit_Click = {
#$mainRichTextbox1.ForeColor = [Drawing.Color]::$($global:textcolor)
$mainRichTextbox1.SelectionColor='red'
$mainRichTextbox1.AppendText("$($mainTextbox1.text)`n")
The property 'SelectionColor' cannot be found on this object. Verify that the property exists and can be set.
MainForm.psf (44, 2): ERROR: At Line: 44 char: 2
ERROR: + $mainRichTextbox1.SelectionColor='red'
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : PropertyAssignmentException
ERROR:
Heres the updated snippet.
$mainButtonSubmit_Click = {
#$mainRichTextbox1.ForeColor = [Drawing.Color]::$($global:textcolor)
$mainRichTextbox1.SelectionColor='red'
$mainRichTextbox1.AppendText("$($mainTextbox1.text)`n")
Re: Adding new lines to RichTextbox with different colors
Did you actually try and run my example. It works so your form must not be using a richtextbox.
"SelectionColor" is not a command. It is a property.
"SelectionColor" is not a command. It is a property.
Re: Adding new lines to RichTextbox with different colors
My apologies for using the incorrect terminology, I am still learning.
Thank you I was not apparently using a richtextbox, I was using a normal textbox.
Once I changed it to a richtextbox things started working as expected.
Thanks again for the help
Thank you I was not apparently using a richtextbox, I was using a normal textbox.
Once I changed it to a richtextbox things started working as expected.
Thanks again for the help