Results 1 to 7 of 7

Thread: hyperlink in text box

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    hyperlink in text box

    is it possible to put a hyperlink in a textbox?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: hyperlink in text box

    Providing there was nothing else in the textbox, it would be very easy.

    If, however, the textbox was loaded with text, one line of which was a hyperlink, then you need to go to a richtextbox. This has the capability of singling out individual lines of text and taking some type of action on them.

  3. #3
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: hyperlink in text box

    I am really not sure what you mean.
    If you have nothing more then the website in it you can, but if you have other text in it then the richtextbox is the way.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    4. Private Const SW_SHOWNORMAL = 1
    5. Private Const SW_SHOWMAXIMIZED = 3
    6.  
    7. Private Sub Form_Load()
    8. Text1.Text = "www.vbforums.com"
    9. End Sub
    10.  
    11. Private Sub Text1_Click()
    12.     ShellExecute ByVal 0&, "open", "http://www.vbforums.com/", _
    13.         vbNullString, vbNullString, SW_SHOWNORMAL
    14. End Sub
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: hyperlink in text box

    i mean like

    Text2.Text = www.hotmail.com

    and i want that text to be hyperlinked (as in go blue and underlines) so users can click on the text and the hotmail page will open

  5. #5
    New Member
    Join Date
    Mar 2006
    Posts
    6

    Re: hyperlink in text box

    You may want to check out my post. the code seems similiar...
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    4.  
    5. Const SW_SHOWNORMAL = 1
    6.  
    7. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    8. Private Const FLAG_ICC_FORCE_CONNECTION = &H1
    9.  
    10. Private Sub Form_Load()
    11.     load_site
    12. End Sub
    13. Public Function load_site()
    14. If InternetCheckConnection("http://www.vbforums.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
    15.                 'There is no connection to site
    16.        MsgBox App.EXEName & " was unable to connect to site", vbInformation, App.EXEName
    17.     Else
    18.         ShellExecute Me.hwnd, "open", "www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL
    19.     End If
    20. End Function
    21.  
    22. 'if you  take out the portion
    23.  
    24. "If InternetCheckConnection("http://youraddresshere.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
    25.                 'There is no connection to site
    26.        MsgBox App.EXEName & " was unable to establish a valid internet connection", vbInformation, App.EXEName
    27.     Else
    28.         ShellExecute Me.hwnd, "open", "http://youraddresshere.com", vbNullString, "C:\", SW_SHOWNORMAL
    29.     End If"
    and add it to a command button, it will launch the site in question. hope this helped.

    btw the above code was not created by me, so credit is due.
    Last edited by Hack; Mar 6th, 2006 at 07:23 AM. Reason: Added [vbcode] [/vbcode] tags and for more clarity.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: hyperlink in text box

    See Rhinobull's example project here

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: hyperlink in text box

    If its the only text in the textbox then you can do it without a RTB. Just in the MouseMove event change the font style so its underlines and change the forecolor. Then when it moves out restore the original font serttings.

    Use the Click example code already posted to execute the link.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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