Active links inside of a Label

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 7 years and 6 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
jpbobrek
Posts: 25
Last visit: Sat Dec 23, 2023 1:52 pm

Active links inside of a Label

Post by jpbobrek »

I want to make the links highlighted in the attachment active links. All of the text in the form is inside of a "Label" control. Is the only way to make links active is by overlaying "LinkLabel" controls? My challenge with the LinkLabel control is that the verbiage in the form changes based on situation and aligning the LinkLabel controls seems like its going to be tricky.
Attachments
2016-08-29_11-08-40.png
2016-08-29_11-08-40.png (29 KiB) Viewed 3702 times
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Active links inside of a Label

Post by dan.potter »

I would use a richtextbox for this.
User avatar
jpbobrek
Posts: 25
Last visit: Sat Dec 23, 2023 1:52 pm

Re: Active links inside of a Label

Post by jpbobrek »

I don't see how a RichTextBox would help. Does RichTextBox allow me to embed links?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Active links inside of a Label

Post by jvierra »

kerbob wrote:I don't see how a RichTextBox would help. Does RichTextBox allow me to embed links?
Have you tried it?

The links are automatically detected and colorized. They are not active. To activate you would have to detect a click ad look to see if it is on a link.
User avatar
jpbobrek
Posts: 25
Last visit: Sat Dec 23, 2023 1:52 pm

Re: Active links inside of a Label

Post by jpbobrek »

Thanks to both of you. After trying, I see that I can enable DetectURLS and use the LinkClicked event handler. Still trying to figure out how to do this correctly.

Just figured it out..

$richtextbox1_LinkClicked=[System.Windows.Forms.LinkClickedEventHandler]{
[System.Diagnostics.Process]::Start($_.LinkText)
}

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

Re: Active links inside of a Label

Post by jvierra »

Great. I was just looking that up but you beat me to it.
User avatar
jpbobrek
Posts: 25
Last visit: Sat Dec 23, 2023 1:52 pm

Re: Active links inside of a Label

Post by jpbobrek »

Now I have a need to put a link to a page using one of those ugly sharepoint links.

For example:
https://xyz.xyz.xyz.com/Lists/Topics/Di ... 4B38EE6C4C

I don't want to put this ugly link in my Rich Textbox.
Is there any way to make a "Click Here to go the web page." and embed the link? If there is, an example is worth a 1000 words.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Active links inside of a Label

Post by jvierra »

What is "Click Here"?
User avatar
jpbobrek
Posts: 25
Last visit: Sat Dec 23, 2023 1:52 pm

Re: Active links inside of a Label

Post by jpbobrek »

Example Rich TextBox content:
---------
Click Here to go to a really long funky URL that I don't want to paste in my Rich Textbox.
---------

When the user clicks "Click Here", I want it to take them to https://xyz.xyz.xyz.com/Lists/Topics/Di ... 4B38EE6C4C.
The point is.. I'm trying to hide an ugly link. Is there a way to do this in Rich TextBox?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Active links inside of a Label

Post by jvierra »

No. RTB can highlight a URL but it cannot process HTML. You can use a LinkLabel control to display text instead of the link.
This topic is 7 years and 6 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