VB搜索一个文件夹内的文档并打开~

VB在窗口Form1里面加入一个写字框,然后和一个按钮.在写字框里输入文字,点按钮,就会在一个文件夹内搜索和写字框内的文字有关的一个文档名并打开这个文档?... VB在窗口Form1里面加入一个写字框,然后和一个按钮.在写字框里输入文字,点按钮,就会在一个文件夹内搜索和写字框内的文字有关的一个文档名并打开这个文档? 展开
 我来答
tianqing20wen

2009-09-11 · TA获得超过2.4万个赞
知道大有可为答主
回答量:8226
采纳率:88%
帮助的人:5077万
展开全部
将以下内容复制到记事本另存为 1.frm文件后打开即可

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3570
ClientLeft = 60
ClientTop = 450
ClientWidth = 5010
LinkTopic = "Form1"
ScaleHeight = 3570
ScaleWidth = 5010
StartUpPosition = 3 '窗口缺省
Begin VB.ListBox List1
Height = 2220
Left = 2640
TabIndex = 5
Top = 1080
Width = 2175
End
Begin VB.FileListBox File1
Height = 1530
Left = 120
TabIndex = 4
Top = 1920
Width = 2295
End
Begin VB.DriveListBox Drive1
Height = 300
Left = 120
TabIndex = 3
Top = 120
Width = 2295
End
Begin VB.CommandButton Command1
Caption = "Find"
Height = 375
Left = 4080
TabIndex = 2
Top = 120
Width = 735
End
Begin VB.DirListBox Dir1
Height = 1350
Left = 120
TabIndex = 1
Top = 480
Width = 2415
End
Begin VB.TextBox Text1
Height = 375
Left = 2640
TabIndex = 0
Top = 120
Width = 1215
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "双击以下列表项打开:"
Height = 180
Left = 2760
TabIndex = 6
Top = 720
Width = 1800
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
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 Command1_Click()
Dim i As Integer
For i = 0 To File1.ListCount - 1
If InStr(UCase(File1.List(i)), UCase(Text1.Text)) > 0 Then
List1.AddItem File1.Path & IIf(Right(File1.Path, 1) = "\", "", "\") & File1.List(i)
End If
Next
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub

Private Sub Form_Load()
File1.Pattern = "*.Txt"' 自行更改欲搜索文件类型
SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, 1000, ByVal 0&
End Sub

Private Sub List1_DblClick()
ShellExecute Me.hwnd, "open", List1.List(List1.ListIndex), "", "", 5
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式