Results 1 to 6 of 6

Thread: Want a hyperlink control

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2017
    Location
    UK, France, Belgium, Ireland
    Posts
    34

    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.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Addicted Member
    Join Date
    Jul 2017
    Location
    Exeter, UK
    Posts
    180

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Want a hyperlink control

    Quote Originally Posted by ktrammen View Post
    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2017
    Location
    UK, France, Belgium, Ireland
    Posts
    34

    Re: Want a hyperlink control

    Quote Originally Posted by techgnome View Post
    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.

    Quote Originally Posted by bmwpete View Post
    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?)

    Quote Originally Posted by jmcilhinney View Post
    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?

    Quote Originally Posted by jmcilhinney View Post
    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.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Want a hyperlink control

    Quote Originally Posted by ktrammen View Post
    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
  •  



Click Here to Expand Forum to Full Width