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.
User avatar
kerbob
Posts: 25
Joined: Sun Mar 03, 2013 12:39 pm

Active links inside of a Label

Post by kerbob » Mon Aug 29, 2016 8:46 am

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 1789 times

User avatar
dan.potter
Posts: 709
Joined: Wed Oct 08, 2014 6:02 am

Re: Active links inside of a Label

Post by dan.potter » Mon Aug 29, 2016 9:03 am

I would use a richtextbox for this.

User avatar
kerbob
Posts: 25
Joined: Sun Mar 03, 2013 12:39 pm

Re: Active links inside of a Label

Post by kerbob » Tue Aug 30, 2016 10:18 pm

I don't see how a RichTextBox would help. Does RichTextBox allow me to embed links?

jvierra
Posts: 14014
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Active links inside of a Label

Post by jvierra » Wed Aug 31, 2016 4:07 am

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
kerbob
Posts: 25
Joined: Sun Mar 03, 2013 12:39 pm

Re: Active links inside of a Label

Post by kerbob » Thu Sep 01, 2016 8:40 pm

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: 14014
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Active links inside of a Label

Post by jvierra » Thu Sep 01, 2016 8:55 pm

Great. I was just looking that up but you beat me to it.

User avatar
kerbob
Posts: 25
Joined: Sun Mar 03, 2013 12:39 pm

Re: Active links inside of a Label

Post by kerbob » Tue Sep 13, 2016 7:17 pm

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: 14014
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Active links inside of a Label

Post by jvierra » Tue Sep 13, 2016 7:23 pm

What is "Click Here"?

User avatar
kerbob
Posts: 25
Joined: Sun Mar 03, 2013 12:39 pm

Re: Active links inside of a Label

Post by kerbob » Tue Sep 13, 2016 8:44 pm

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: 14014
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Active links inside of a Label

Post by jvierra » Tue Sep 13, 2016 9:26 pm

No. RTB can highlight a URL but it cannot process HTML. You can use a LinkLabel control to display text instead of the link.

Locked