Richtextbox: set only specific text in bold and/or other color

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.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Richtextbox: set only specific text in bold and/or other color

Post by stevens »

Hi,

I have a richtextbox in which I'd like to set only specific text to bold and/or red color.

I now have f.e. richtextbox1.text += 'MyText'
If I'd like to add $richtextbox1.text += 'MyTextBold', how do I do that?
Tried with $richtextbox1.SelectionFont.Bold = $true but it says it is readonly(?)


Thanks!
S.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Richtextbox: set only specific text in bold and/or other color

Post by jvierra »

Start by reading the documentation for the RTB and read how to use the methods and decide whether to use RTF strings or to use primitives.

Everything you asked is on this page: https://docs.microsoft.com/en-us/dotnet ... esktop-6.0
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Richtextbox: set only specific text in bold and/or other color

Post by jvierra »

Here is an RTB sampler I built years ago to demonstrate various methods useful with an RTB.
Attachments
Demo-RTFColors.psf
(22.45 KiB) Downloaded 92 times
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked