Google是我们使用最为普遍的搜索引擎,我们怎么把它内置到VS.NET中那?这里用到了Visual Studio .NET 的宏,利用这个可以实现内置Google工具条嵌在VS.NET中.
在VS.NET的宏编辑器(alt+F11打开)中新建一个Modle(MyMacros工程中),代码如下: Search.VB
Imports EnvDTE
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Globalization
Public Module Search
Public Sub Google()
NavigateTo("http://www.google.com/search?q={0}")
End Sub
Private Sub NavigateTo(ByVal url As String)
Dim selection As String = DTE.ActiveDocument.Selection.Text
If selection.Length > 0 Then
DTE.ItemOperations.Navigate(String.Format(CultureInfo.InvariantCulture, url, selection), vsNavigateOptions.vsNavigateOptionsNewWindow)
Else
MessageBox.Show("No search text selected.")
End If
End Sub
End Module
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Globalization
Public Module Search
Public Sub Google()
NavigateTo("http://www.google.com/search?q={0}")
End Sub
Private Sub NavigateTo(ByVal url As String)
Dim selection As String = DTE.ActiveDocument.Selection.Text
If selection.Length > 0 Then
DTE.ItemOperations.Navigate(String.Format(CultureInfo.InvariantCulture, url, selection), vsNavigateOptions.vsNavigateOptionsNewWindow)
Else
MessageBox.Show("No search text selected.")
End If
End Sub
End Module
将这个宏添加到工具条中.
具体的操作参考: dotnetjunkies上的Add a search engine toolbar to VS.NET
支持中文:
DTE.ItemOperations.Navigate(String.Format(CultureInfo.InvariantCulture, url, System.Web.HttpUtility.UrlPathEncode(selection)), vsNavigateOptions.vsNavigateOptionsNewWindow)
具体的操作参考: dotnetjunkies上的Add a search engine toolbar to VS.NET
支持中文:
DTE.ItemOperations.Navigate(String.Format(CultureInfo.InvariantCulture, url, System.Web.HttpUtility.UrlPathEncode(selection)), vsNavigateOptions.vsNavigateOptionsNewWindow)