clickable entries in RichTextBox

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
boyddt_co
Posts: 89
Last visit: Wed Jul 14, 2021 6:48 am

clickable entries in RichTextBox

Post by boyddt_co »

I am creating a site/server checking application and the end users decided that if a site/server fails they want to be able to click on it and get a tracert outputted. What are my options to have a link embedded in the RTB field? I've included a screenshot. So, in this example, they would want to click on Web Server and open a window that would run test-netconnection -tracert command.
SiteChecker.PNG
SiteChecker.PNG (9.68 KiB) Viewed 2412 times

jvierra
Posts: 14883
Last visit: Sat Jul 31, 2021 1:54 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: clickable entries in RichTextBox

Post by jvierra »

I recommend using a ListView control as it has better support for links when displayed as a hierarchy.

User avatar
boyddt_co
Posts: 89
Last visit: Wed Jul 14, 2021 6:48 am

Re: clickable entries in RichTextBox

Post by boyddt_co »

Thank you, I will give that a try.

User avatar
boyddt_co
Posts: 89
Last visit: Wed Jul 14, 2021 6:48 am

Re: clickable entries in RichTextBox

Post by boyddt_co »

So I'm trying the listview box and it isn't working as expected. Using the add-listviewitem code that is automatically added, entries are duplicated. In the picture you can see the output to the GUI and the output to the console. The code where I call the add-listviewitem is included.

Sapien_ListView.PNG
Sapien_ListView.PNG (31.08 KiB) Viewed 1965 times
  1. $SitePing = $global:SiteDict[$TestCount].SitePing
  2.         $SiteName = $global:SiteDict[$TestCount].SiteName
  3.         $SiteURL = $global:SiteDict[$TestCount].SiteURL
  4.         $SitePorts = $global:SiteDict[$TestCount].Ports -split ","
  5.         $TotalPorts = $SitePorts.Count
  6.         $Path = (Split-Path $script:MyInvocation.MyCommand.Path).replace(" ", "`` ") + "\portqry.exe"
  7.         $listview1.Items.Add($SiteName + "`r`n")
  8.         Write-Host $SiteName
  9.         Add-ListViewItem -ListView $listview1 -Items $SiteName

jvierra
Posts: 14883
Last visit: Sat Jul 31, 2021 1:54 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

Re: clickable entries in RichTextBox

Post by jvierra »

Obviously you event is being called twice for each entry.

Locked