vb如何使用超链接打开网页
发布网友
发布时间:2022-07-25 03:39
我来回答
共4个回答
热心网友
时间:2023-10-11 15:50
方法1)直接使用VB的Shell函数调用explorer.exe来实现。
Private Sub Command2_Click()
Shell "explorer.exe http://" & Text1
End Sub
方法2)使用API函数 ShellExecute实现。
以下是具体代码:
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
Dim strUrl As String
Private Sub OpenUrl(tUrl As String)
ShellExecute Me.hwnd, "Open", tUrl, 0, 0, 0
End Sub
Private Sub Command1_Click()
strUrl = Text1.Text
OpenUrl (strUrl)
End Sub
Private Sub Form_Load()
Text1 = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text1 <> "" Then
Command1_Click
End If
End Sub
方法3)使用WebBrowser控件,直接制作个简易浏览器来实现。
Private Sub Command1_Click()
WebBrowser1.Navigate Text1
End Sub
Private Sub Form_Load()
Text1 = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Text1 <> "" Then
Command1_Click
End If
End Sub
方法3的运行效果图:
热心网友
时间:2023-10-11 15:50
在form1上添加一个文本框text1,添加一个按钮command1用以下语句即可实现:
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 Sub OpenUrl(tUrl As String)
ShellExecute Me.hwnd, "Open", tUrl, 0, 0, 0
End Sub
Private Sub Command1_Click()
str_open = Text1.Text
OpenUrl (str_open)
End Sub
热心网友
时间:2023-10-11 15:50
上面的太麻烦 给你个简单的Private Sub Command4_Click()
Shell "explorer.exe http://xinjunshi.com"
End Sub
热心网友
时间:2023-10-11 15:51
private sub command1_click()
shell "explorer.exe " & text1
end sub