vs2003中宏的应用:快速找页面、多行查找
1、快速找页面:
Imports EnvDTE
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Threading
Public Module QuickFindPage
Dim ClipString As String
Sub QuickFindPage()
'// take whatever is on the clipboard and save it to an xml file
'// intended for cut & paste from QueryAnalyzer
Dim ClipBoardThread As System.Threading.Thread = New System.Threading.Thread(AddressOf getClipString_core)
With ClipBoardThread
.ApartmentState = ApartmentState.STA
.IsBackground = True
.Start()
'-- Wait for copy to happen
.Join()
End With
ClipBoardThread = Nothing
ClipString = Replace(ClipString, "/", "\")
If ClipString <> "" Then
If System.IO.File.Exists(ClipString) Then
DTE.ItemOperations.OpenFile(ClipString)
Else
Dim posControl = InStr(ClipString, ".ascx")
Dim posControl2 = InStr(ClipString, ".aspx")
If (posControl <> 0) Then
Dim ClipString1 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\CO\Control\" & ClipString
Dim ClipString2 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\PO\Control\" & ClipString
Dim ClipString3 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IV\Control\" & ClipString
Dim ClipString4 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IN\Control\" & ClipString
Dim ClipString5 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\SH\Control\" & ClipString
If System.IO.File.Exists(ClipString1) Then
DTE.ItemOperations.OpenFile(ClipString1)
ElseIf System.IO.File.Exists(ClipString2) Then
DTE.ItemOperations.OpenFile(ClipString2)
ElseIf System.IO.File.Exists(ClipString3) Then
DTE.ItemOperations.OpenFile(ClipString3)
ElseIf System.IO.File.Exists(ClipString4) Then
DTE.ItemOperations.OpenFile(ClipString4)
ElseIf System.IO.File.Exists(ClipString5) Then
DTE.ItemOperations.OpenFile(ClipString5)
Else
MessageBox.Show("Can not find the file !")
End If
ElseIf (posControl2 <> 0) Then
Dim ClipString1 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\CO\Page\" & ClipString
Dim ClipString2 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\PO\Page\" & ClipString
Dim ClipString3 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IV\Page\" & ClipString
Dim ClipString4 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IN\Page\" & ClipString
Dim ClipString5 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\SH\Page\" & ClipString
If System.IO.File.Exists(ClipString1) Then
DTE.ItemOperations.OpenFile(ClipString1)
ElseIf System.IO.File.Exists(ClipString2) Then
DTE.ItemOperations.OpenFile(ClipString2)
ElseIf System.IO.File.Exists(ClipString3) Then
DTE.ItemOperations.OpenFile(ClipString3)
ElseIf System.IO.File.Exists(ClipString4) Then
DTE.ItemOperations.OpenFile(ClipString4)
ElseIf System.IO.File.Exists(ClipString5) Then
DTE.ItemOperations.OpenFile(ClipString5)
Else
MessageBox.Show("Can not find the file !")
End If
Else
'虚拟目录名()
Dim VirtualName = "Rhombus2_YEA"
Dim pos = InStr(ClipString, "\" & VirtualName & "\")
If (pos <> 0) Then
ClipString = Right(ClipString, Len(ClipString) - pos - Len("\" & VirtualName & "\") + 1)
End If
pos = InStr(ClipString, "?")
If (pos <> 0) Then
ClipString = Left(ClipString, pos - 1)
End If
'组合成正确的物理路径
ClipString = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\" & ClipString
If System.IO.File.Exists(ClipString) Then
DTE.ItemOperations.OpenFile(ClipString)
Else
MessageBox.Show("Can not find the file !")
End If
End If
End If
End If
End Sub
Sub getClipString_core()
ClipString = Clipboard.GetDataObject().GetData(System.Windows.Forms.DataFormats.StringFormat)
End Sub
End Module
2、多行查找:

Imports EnvDTE
Imports System.Diagnostics
Public Module MultilineSearch
Sub MultilineSearchReplace()
Dim sf As New MultilineSearchForm
sf.ShowDialog()
If sf.result <> FindReplaceKind.none Then
' temporarily disable Tools - Options -
' Environment - Documents - Initialize Find text from editor
Dim oldFindInit As Boolean
Try
Dim props As EnvDTE.Properties
props = DTE.Properties("Environment", "Documents")
Dim prop As EnvDTE.Property = props.Item("FindReplaceInitializeFromEditor")
oldFindInit = prop.Value
prop.Value = False
Catch ex As System.Exception
End Try
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
DTE.Find.FindWhat = sf.findText
DTE.Find.ReplaceWith = sf.replaceText
Select Case sf.result
Case FindReplaceKind.find
DTE.ExecuteCommand("Edit.Find")
Case FindReplaceKind.findInFiles
DTE.ExecuteCommand("Edit.FindinFiles")
Case FindReplaceKind.replace
DTE.ExecuteCommand("Edit.Replace")
Case FindReplaceKind.replaceInFiles
DTE.ExecuteCommand("Edit.ReplaceinFiles")
Case Else
End Select
' restore Tools - Options -
' Environment - Documents - Initialize Find text from editor
Try
Dim props As EnvDTE.Properties
props = DTE.Properties("Environment", "Documents")
Dim prop As EnvDTE.Property = props.Item("FindReplaceInitializeFromEditor")
prop.Value = oldFindInit
Catch ex As System.Exception
End Try
End If
End Sub
End Module
'''<summary>Types of find/replace operations.</summary>
Public Enum FindReplaceKind
'''<summary>Find</summary>
find
'''<summary>Find In Files</summary>
findInFiles
'''<summary>Replace</summary>
replace
'''<summary>Replace in Files</summary>
replaceInFiles
'''<summary>None. Cancel was pressed.</summary>
none
End Enum
Public Class MultilineSearchForm
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents FindBox As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents ReplaceBox As System.Windows.Forms.TextBox
Friend WithEvents FindBtn As System.Windows.Forms.Button
Friend WithEvents FindInFilesBtn As System.Windows.Forms.Button
Friend WithEvents ReplaceBtn As System.Windows.Forms.Button
Friend WithEvents ReplaceInFilesBtn As System.Windows.Forms.Button
Friend WithEvents CancelBtn As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.FindBox = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.ReplaceBox = New System.Windows.Forms.TextBox
Me.FindBtn = New System.Windows.Forms.Button
Me.FindInFilesBtn = New System.Windows.Forms.Button
Me.ReplaceBtn = New System.Windows.Forms.Button
Me.ReplaceInFilesBtn = New System.Windows.Forms.Button
Me.CancelBtn = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'FindBox
'
Me.FindBox.Location = New System.Drawing.Point(16, 24)
Me.FindBox.Multiline = True
Me.FindBox.Name = "FindBox"
Me.FindBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.FindBox.Size = New System.Drawing.Size(400, 80)
Me.FindBox.TabIndex = 0
Me.FindBox.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(160, 16)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Find what:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 112)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(160, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Replace with:"
'
'ReplaceBox
'
Me.ReplaceBox.Location = New System.Drawing.Point(16, 128)
Me.ReplaceBox.Multiline = True
Me.ReplaceBox.Name = "ReplaceBox"
Me.ReplaceBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.ReplaceBox.Size = New System.Drawing.Size(400, 80)
Me.ReplaceBox.TabIndex = 3
Me.ReplaceBox.Text = ""
'
'FindBtn
'
Me.FindBtn.Location = New System.Drawing.Point(16, 232)
Me.FindBtn.Name = "FindBtn"
Me.FindBtn.Size = New System.Drawing.Size(80, 24)
Me.FindBtn.TabIndex = 5
Me.FindBtn.Text = "Find>>"
'
'FindInFilesBtn
'
Me.FindInFilesBtn.Location = New System.Drawing.Point(104, 232)
Me.FindInFilesBtn.Name = "FindInFilesBtn"
Me.FindInFilesBtn.Size = New System.Drawing.Size(96, 24)
Me.FindInFilesBtn.TabIndex = 6
Me.FindInFilesBtn.Text = "Find in Files>>"
'
'ReplaceBtn
'
Me.ReplaceBtn.Location = New System.Drawing.Point(216, 232)
Me.ReplaceBtn.Name = "ReplaceBtn"
Me.ReplaceBtn.Size = New System.Drawing.Size(80, 24)
Me.ReplaceBtn.TabIndex = 7
Me.ReplaceBtn.Text = "Replace>>"
'
'ReplaceInFilesBtn
'
Me.ReplaceInFilesBtn.Location = New System.Drawing.Point(304, 232)
Me.ReplaceInFilesBtn.Name = "ReplaceInFilesBtn"
Me.ReplaceInFilesBtn.Size = New System.Drawing.Size(112, 24)
Me.ReplaceInFilesBtn.TabIndex = 8
Me.ReplaceInFilesBtn.Text = "Replace in Files>>"
'
'CancelBtn
'
Me.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.CancelBtn.Location = New System.Drawing.Point(168, 272)
Me.CancelBtn.Name = "CancelBtn"
Me.CancelBtn.Size = New System.Drawing.Size(80, 24)
Me.CancelBtn.TabIndex = 9
Me.CancelBtn.Text = "Cancel"
'
'MultilineSearchForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.CancelBtn
Me.ClientSize = New System.Drawing.Size(432, 310)
Me.Controls.Add(Me.CancelBtn)
Me.Controls.Add(Me.ReplaceInFilesBtn)
Me.Controls.Add(Me.ReplaceBtn)
Me.Controls.Add(Me.FindInFilesBtn)
Me.Controls.Add(Me.FindBtn)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.ReplaceBox)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.FindBox)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow
Me.Name = "MultilineSearchForm"
Me.Text = "Multiline Search and Replace"
Me.ResumeLayout(False)
End Sub
#End Region
#Region "Properties"
Private m_result As FindReplaceKind = FindReplaceKind.none
'''<summary>Gets result button from this dialog.</summary>
'''<value>The value specifying which button was pressed.</value>
Public ReadOnly Property result() As FindReplaceKind
Get
Return m_result
End Get
End Property
Private m_findText As String
'''<summary>Gets escaped multiline text to be searched.</summary>
'''<value></value>
Public ReadOnly Property findText() As String
Get
Return m_findText
End Get
End Property
Private m_replaceText As String
'''<summary>Gets escaped multiline replace text.</summary>
'''<value></value>
Public ReadOnly Property replaceText() As String
Get
Return m_replaceText
End Get
End Property
#End Region
'''<summary>Transforms the text to regular expression syntax.</summary>
'''<param name="original">Original text.</param>
'''<returns>Text with escaped regex characters.</returns>
Private Function escapeRegEx(ByVal original As String) As String
Dim specialChars() As Char = "\.*+^___FCKpd___0gt;<[]|{}:@#()~".ToCharArray
Dim c As Char
For Each c In specialChars
original = original.Replace(c.ToString, "\" & c.ToString)
Next
original = original.Replace(vbCrLf, "\n")
Return original
End Function
Private Sub MultilineSearchForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Me.Activate()
Catch ex As System.Exception
End Try
End Sub
Private Sub CancelBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelBtn.Click
Try
m_result = FindReplaceKind.none
Me.Close()
Catch ex As System.Exception
End Try
End Sub
Private Sub FindBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindBtn.Click
Try
m_findText = escapeRegEx(Me.FindBox.Text)
m_replaceText = escapeRegEx(Me.ReplaceBox.Text)
m_result = FindReplaceKind.find
Me.Close()
Catch ex As System.Exception
End Try
End Sub
Private Sub FindInFilesBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindInFilesBtn.Click
Try
m_findText = escapeRegEx(Me.FindBox.Text)
m_replaceText = escapeRegEx(Me.ReplaceBox.Text)
m_result = FindReplaceKind.findInFiles
Me.Close()
Catch ex As System.Exception
End Try
End Sub
Private Sub ReplaceBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReplaceBtn.Click
Try
m_findText = escapeRegEx(Me.FindBox.Text)
m_replaceText = escapeRegEx(Me.ReplaceBox.Text)
m_result = FindReplaceKind.replace
Me.Close()
Catch ex As System.Exception
End Try
End Sub
Private Sub ReplaceInFilesBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReplaceInFilesBtn.Click
Try
m_findText = escapeRegEx(Me.FindBox.Text)
m_replaceText = escapeRegEx(Me.ReplaceBox.Text)
m_result = FindReplaceKind.replaceInFiles
Me.Close()
Catch ex As System.Exception
End Try
End Sub
End Class

Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Threading
Public Module QuickFindPage
Dim ClipString As String
Sub QuickFindPage()
'// take whatever is on the clipboard and save it to an xml file
'// intended for cut & paste from QueryAnalyzer
Dim ClipBoardThread As System.Threading.Thread = New System.Threading.Thread(AddressOf getClipString_core)
With ClipBoardThread
.ApartmentState = ApartmentState.STA
.IsBackground = True
.Start()
'-- Wait for copy to happen
.Join()
End With
ClipBoardThread = Nothing
ClipString = Replace(ClipString, "/", "\")
If ClipString <> "" Then
If System.IO.File.Exists(ClipString) Then
DTE.ItemOperations.OpenFile(ClipString)
Else
Dim posControl = InStr(ClipString, ".ascx")
Dim posControl2 = InStr(ClipString, ".aspx")
If (posControl <> 0) Then
Dim ClipString1 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\CO\Control\" & ClipString
Dim ClipString2 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\PO\Control\" & ClipString
Dim ClipString3 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IV\Control\" & ClipString
Dim ClipString4 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IN\Control\" & ClipString
Dim ClipString5 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\SH\Control\" & ClipString
If System.IO.File.Exists(ClipString1) Then
DTE.ItemOperations.OpenFile(ClipString1)
ElseIf System.IO.File.Exists(ClipString2) Then
DTE.ItemOperations.OpenFile(ClipString2)
ElseIf System.IO.File.Exists(ClipString3) Then
DTE.ItemOperations.OpenFile(ClipString3)
ElseIf System.IO.File.Exists(ClipString4) Then
DTE.ItemOperations.OpenFile(ClipString4)
ElseIf System.IO.File.Exists(ClipString5) Then
DTE.ItemOperations.OpenFile(ClipString5)
Else
MessageBox.Show("Can not find the file !")
End If
ElseIf (posControl2 <> 0) Then
Dim ClipString1 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\CO\Page\" & ClipString
Dim ClipString2 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\PO\Page\" & ClipString
Dim ClipString3 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IV\Page\" & ClipString
Dim ClipString4 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\IN\Page\" & ClipString
Dim ClipString5 = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\SH\Page\" & ClipString
If System.IO.File.Exists(ClipString1) Then
DTE.ItemOperations.OpenFile(ClipString1)
ElseIf System.IO.File.Exists(ClipString2) Then
DTE.ItemOperations.OpenFile(ClipString2)
ElseIf System.IO.File.Exists(ClipString3) Then
DTE.ItemOperations.OpenFile(ClipString3)
ElseIf System.IO.File.Exists(ClipString4) Then
DTE.ItemOperations.OpenFile(ClipString4)
ElseIf System.IO.File.Exists(ClipString5) Then
DTE.ItemOperations.OpenFile(ClipString5)
Else
MessageBox.Show("Can not find the file !")
End If
Else
'虚拟目录名()
Dim VirtualName = "Rhombus2_YEA"
Dim pos = InStr(ClipString, "\" & VirtualName & "\")
If (pos <> 0) Then
ClipString = Right(ClipString, Len(ClipString) - pos - Len("\" & VirtualName & "\") + 1)
End If
pos = InStr(ClipString, "?")
If (pos <> 0) Then
ClipString = Left(ClipString, pos - 1)
End If
'组合成正确的物理路径
ClipString = "D:\Rhombus2\2-Software Development\4-Software Implementation\2-Source Files\Source DEV\RhombusSolution\Rhombus2\" & ClipString
If System.IO.File.Exists(ClipString) Then
DTE.ItemOperations.OpenFile(ClipString)
Else
MessageBox.Show("Can not find the file !")
End If
End If
End If
End If
End Sub
Sub getClipString_core()
ClipString = Clipboard.GetDataObject().GetData(System.Windows.Forms.DataFormats.StringFormat)
End Sub
End Module
2、多行查找:































































































































































































































































































如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?