Results 1 to 7 of 7

Thread: Adding web links to a form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    17

    Adding web links to a form

    Hi all,

    I would like to get the web links from a database and display on the form. When the user clicks the link Internet Explorer opens and goes to the link. Do you know how I can do this? In which tool box element must I put the link content ? (label or what? it is not label but what then )

    Thank you

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Adding web links to a form

    Based on your other posts I see you are using VB - which is not the same as VBScript, so I have moved this thread from the ASP/VB Script forum.

    You can use any control you like for this.. none of them actually do the work for you, but it is easy enough to add it yourself.

    The way to do it is shown in the thread How do I open a file/web-page in its default application? from our Classic VB FAQ's (link in my signature).

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Adding web links to a form

    What you do to make it look like a link is....

    1) Add a Label, call it "lblLink"

    2) Change the Font of the link to the color Blue, and add underline

    3) Double click it and add the code:
    VB Code:
    1. 'in General-Declarations:
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal lpOperation As String, _
    5.     ByVal lpFile As String, _
    6.     ByVal lpParameters As String, _
    7.     ByVal lpDirectory As String, _
    8.     ByVal nShowCmd As Long) As Long
    9.  
    10.  
    11. 'Example code:
    12.      'open a file
    13.   ShellExecute Me.hWnd, "open", "c:\My folder\Test.doc", vbNullString, "C:\", ByVal 1&
    14.  
    15.      'open a web page
    16.   ShellExecute Me.hWnd, "open", "http://www.VBForums.com", vbNullString, "C:\", ByVal 1&
    My usual boring signature: Something

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    17

    Re: Adding web links to a form

    It is going to be a loop and will get the web sites from a database? Does it make a difference?

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Adding web links to a form

    That's fine, and actually irrelevant.. once the address is in your program (in a variable or control), you can open the page.

    To open the web page you just need to pass the address to OpenURL (if you are using the Sub from the FAQ thread), or put it in place of the hard-coded address if you are using the part of the FAQ that dclamp re-posted.

    If you have the OpenURL sub and the address is in Label1.Caption, you can simply use this:
    VB Code:
    1. OpenURL Label1.Caption

  6. #6
    Frenzied Member zynder's Avatar
    Join Date
    Nov 2006
    Location
    localhost
    Posts
    1,434

    Re: Adding web links to a form

    You may also want to change your mouse icon to a hand sorta link.

  7. #7
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Adding web links to a form

    Quote Originally Posted by zynder
    You may also want to change your mouse icon to a hand sorta link.
    Yea

    You can use your own custom cursor or find them in %windir%\cursors (C:\Windows\Cursors)

    Just set the label's MouseIcon property to the cursor file, and it's MousePointer property to 'Custom'

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