-
Mar 5th, 2018, 10:56 AM
#1
Thread Starter
Member
Want a hyperlink control
This is a quickie because I'm sure this has a very simple answer (yet I cannot see it).
I want to put a hyperlink onto a Windows form. From hunting, there's this LinkLabel control that one is supposed to use. It's got all sorts of properties one would expect of a hyperlink EXCEPT a property for the actual URL itself!
Am I supposed to use a different sort of control, or is there some property I'm just not seeing?
EDIT: To clarify: it's simply a label, or text box, or similar, that displays text for a link that, when clicked, opens a browser window that opens up with the corresponding web page for that link.
EDIT 2: Was trying to post an example from html using anchor tags with a link text and link URL but VBForums won't allow it.
EDIT 3: I have spent an hour now trying to find a solution (including quite a bit of time trying to post the question on this forum!) It's so simple in MS Access.
EDIT 4: I have found a solution, which is to use System.Diagnostics.Process.Start("http://www.example.com") but it looks absurd. Surely there should be a simpler solution?
Last edited by ktrammen; Mar 5th, 2018 at 11:35 AM.
-
Mar 5th, 2018, 11:30 AM
#2
Re: Want a hyperlink control
That's because it does more than it probably should... it's got a Links (plural) property that stores a collection of links... I don't know why... seems like it should be a lot simpler than that....
But here's a link to the documentation of the Links property, that has an example - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx it actually uses the collection, but I imagine it could be simplified a bit and only have one link added to it. I have used it before and set it all up at design time, so it can be done, it's just been a while, so I don't remember specifically how I did it.
-tg
-
Mar 5th, 2018, 11:39 AM
#3
Addicted Member
Re: Want a hyperlink control
You can use the .Tag property, set at design time, then call Process start with that value,
Code:
Private Sub Lnk_Label_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Lnk_Label.LinkClicked
Process.Start(Lnk_Label.Tag)
End Sub
-
Mar 5th, 2018, 09:59 PM
#4
Re: Want a hyperlink control
Originally Posted by ktrammen
I have found a solution, which is to use System.Diagnostics.Process.Start("http://www.example.com") but it looks absurd. Surely there should be a simpler solution?
Why should there be a simpler way? A LinkLabel is basically just a button. Just as with a Button control, you can do absolutely anything when a LinkLabel is clicked. Just because you want to open a browser window to a URL is no indication that everyone else does too. What if you want to open that URL in a WebBrowser control, or display another form, or something else entirely? How would the LinkLabel control provide a simpler solution for doing any or all of those things?
The one thing you can do is drop the System.Diagnostics, because that namespace is already imported by default.
-
Mar 6th, 2018, 08:19 AM
#5
Thread Starter
Member
Re: Want a hyperlink control
Originally Posted by techgnome
That's because it does more than it probably should... it's got a Links (plural) property that stores a collection of links... I don't know why... seems like it should be a lot simpler than that....
But here's a link to the documentation of the Links property, that has an example - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx it actually uses the collection, but I imagine it could be simplified a bit and only have one link added to it. I have used it before and set it all up at design time, so it can be done, it's just been a while, so I don't remember specifically how I did it.
-tg
Thanks, yes, came across that. Overcomplicated because 99% of the time one only wants one link per control.
Originally Posted by bmwpete
You can use the .Tag property, set at design time, then call Process start with that value,
Code:
Private Sub Lnk_Label_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles Lnk_Label.LinkClicked
Process.Start(Lnk_Label.Tag)
End Sub
Forgot about the tag property. But I always used to avoid it because it feels a bit Mickey Mouse. (What if one were to want to have more than one thing type of thing in thing in the tag property?)
Originally Posted by jmcilhinney
Why should there be a simpler way? A LinkLabel is basically just a button. Just as with a Button control, you can do absolutely anything when a LinkLabel is clicked. Just because you want to open a browser window to a URL is no indication that everyone else does too. What if you want to open that URL in a WebBrowser control, or display another form, or something else entirely? How would the LinkLabel control provide a simpler solution for doing any or all of those things?
There should be a simpler way because it is surely something one often wants to do. As I indicated in my original post, MS Access has a nice, simple hyperlink control - it's one of the few, simple controls shown on Access's form design "control strip"(?). Actually, Access's hyperlink control is a label control with knobs on presumably because Microsoft didn't want to go to the trouble of developing a separate hyperlink control. However, with Visual Studio, their developers are clearly on triple espressos, with crack as their sugar, because they keep on developing controls with vast numbers of arcane properties and methods. If they have time to pour into developing all these controls that I bet are mostly not used, why not develop something useful?
Originally Posted by jmcilhinney
The one thing you can do is drop the System.Diagnostics, because that namespace is already imported by default.
Thanks re dropping the System.Diagnostics. Always like to declutter code.
-
Mar 6th, 2018, 08:24 AM
#6
Re: Want a hyperlink control
Originally Posted by ktrammen
If they have time to pour into developing all these controls that I bet are mostly not used, why not develop something useful?
Of course you're right. Only what you want to do could be considered useful and stuff everyone else. What proportion of LinkLabel controls are used to open a URL in a browser and what proportion are used for other things? I'll wager that you don't know, in which case your opinion about whether that's the only useful thing they could do should be treated accordingly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|