不用你那么麻烦的,只是记事本的查找的话很简单,下面的代码就可以完成你的要求Dim sFile As String
Private Sub mnuFindOn_Click()
sfind = InputBox("请输入你要查找的信息?", , sfind)
RichTextBox1.Find sfind
End Sub
Private Sub mnuFindOn_Click()
sfind = InputBox("请输入你要查找的信息?", , sfind)
RichTextBox1.Find sfind
End Sub
解决方案 »
- VSFlexGrid滚轮滚动
- vb6.0 中怎么书写一大段的SQL语句
- 如何获得当前得到焦点的控件
- 急!!_100分相送!!!水晶报表做到由客户选择要显示的字段进行自定义显示的问题
- 在VB6.0中picturebox或image控件如何显示地址在Text控件中图片?
- 请教高手指点关于adodc对象保存
- 如何将在vb中编写的一段宏写入一个excel文件呢?
- 数据库中改变记录数的问题。(急急........)请高手帮忙
- 各位大哥大姐 我有一个关于窗口的问题! 帮帮我~~谢谢!
- 有这样一个问题,请诸位指教
- 急急!!快来帮忙看一下...
- 请指教 select带参数的语句,用Execute方法执行后,如何返回结果,如有多少条记录?
在一般的文本编辑软件中,例如 Windows 本身提供的记事本及写字板中,我们都可以在【编辑】下拉菜单中,找到【查找】、【替换】二项功能,我想很多人自己在编写程序时,也都会自己为程序去编写这二个相当基本的功能。其实根本不用您自己花时间去编写这样的程序代码!还记得 Microsoft Common Dialog Control (16 位控件是 Comdlg16.ocx,32 位控件是 Comdlg32.ocx) 吗?我们都知道,这个控件可以帮助我们做到以下几件事情:1、ShowOpen:打开文件对话框
2、ShowSave:保存对话框
3、ShowPrinter:打印设置对话框
4、ShowFont:字体对话框
5、ShowColor:颜色对话框
6、ShowHelp:帮助对话框
当然,您若还想要 Microsoft Common Dialog Control 多做一些別的事也没办法的!但是,Microsoft 在提供 .ocx 控件的同时,还提供了另外一个控件文档,也就是 comdlg32.dll,它的功能就多了,除了上面提到的几种对话框之外,还有好几个不同功能的对话框,其中就包含【查找】、【替换】二项功能!这二个 API 分別是 FindText 及 ReplaceText 二个。在程序中,要声明这二个 API 之前,由于它们都会引用到一个名为 FINDREPLACE 的 Type,所以我们在声明 Function 之前,必须先声明 Type FINDREPLACE,程序代码如下:在表单的声明区中加入以下声明:'Find/Replace Type Structure
Private Type FINDREPLACE
lStructSize As Long ' size of this struct 0x20
hwndOwner As Long ' handle to owner's window
hInstance As Long ' instance handle of.EXE that contains cust. dlg. template
flags As Long ' one or more of the FR_??
lpstrFindWhat As String ' ptr. to search string
lpstrReplaceWith As String ' ptr. to replace string
wFindWhatLen As Integer ' size of find buffer
wReplaceWithLen As Integer ' size of replace buffer
lCustData As Long ' data passed to hook fn.
lpfnHook As Long ' ptr. to hook fn. or NULL
lpTemplateName As String ' custom template name
End Type'Common Dialog DLL Calls
Private Declare Function FindText Lib "comdlg32.dll" Alias "FindTextA" _
(pFindreplace As FINDREPLACE) As LongPrivate Declare Function ReplaceText Lib "comdlg32.dll" Alias "ReplaceTextA" _
(pFindreplace As FINDREPLACE) As Long'Delcaration of the type structure
Dim frText As FINDREPLACE
在表单中加入二个 Command Button,并命名为 cmdFind, cmdReplace,加入以下程序代码:Private Sub cmdFind_Click()
'Call the find text function
FindText frText
End SubPrivate Sub cmdReplace_Click()
'Call the replace text function
ReplaceText frText
End SubPrivate Sub Form_Load()
'Set the Find/Replace Type properties
With frText
.lpstrReplaceWith = "Replace Text"
.lpstrFindWhat = "Find Text"
.wFindWhatLen = 9
.wReplaceWithLen = 12
.hInstance = App.hInstance
.hwndOwner = Me.hWnd
.lStructSize = LenB(frText)
End With
End Sub
好了,您现在可以按 F5 试试了!
注:在 Type FINDREPLACE 中有一个 flag,您可以代入的 flag 是 FR_??,您可以在 API 文件查看器中找找!--------------------------------------------------------------------------------