is it possible to put a hyperlink in a textbox?
Printable View
is it possible to put a hyperlink in a textbox?
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.
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:
Option Explicit 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 Private Const SW_SHOWNORMAL = 1 Private Const SW_SHOWMAXIMIZED = 3 Private Sub Form_Load() Text1.Text = "www.vbforums.com" End Sub Private Sub Text1_Click() ShellExecute ByVal 0&, "open", "http://www.vbforums.com/", _ vbNullString, vbNullString, SW_SHOWNORMAL End Sub
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
You may want to check out my post. the code seems similiar...and add it to a command button, it will launch the site in question. hope this helped.VB Code:
Option Explicit 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 Const SW_SHOWNORMAL = 1 Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long Private Const FLAG_ICC_FORCE_CONNECTION = &H1 Private Sub Form_Load() load_site End Sub Public Function load_site() If InternetCheckConnection("http://www.vbforums.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then 'There is no connection to site MsgBox App.EXEName & " was unable to connect to site", vbInformation, App.EXEName Else ShellExecute Me.hwnd, "open", "www.vbforums.com", vbNullString, "C:\", SW_SHOWNORMAL End If End Function 'if you take out the portion "If InternetCheckConnection("http://youraddresshere.com", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then 'There is no connection to site MsgBox App.EXEName & " was unable to establish a valid internet connection", vbInformation, App.EXEName Else ShellExecute Me.hwnd, "open", "http://youraddresshere.com", vbNullString, "C:\", SW_SHOWNORMAL End If"
btw the above code was not created by me, so credit is due.
See Rhinobull's example project here
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. :)