方法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的运行效果图:
在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
上面的乎乱太岁冲档麻烦 给你个简单的Private Sub Command4_Click()
Shell "判信explorer.exe http://xinjunshi.com"
End Sub
private sub command1_click()
shell "explorer.exe " & text1
end sub