<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-3174602118926954924</atom:id><lastBuildDate>Thu, 29 Dec 2011 19:55:24 +0000</lastBuildDate><category>Regex</category><category>Productivity</category><category>Help</category><category>Visual Studio</category><category>Layout</category><category>Macros</category><category>Presentations</category><title>Brian Schmitt</title><description>IObservable</description><link>http://www.brianschmitt.com/</link><managingEditor>noreply@blogger.com (Brian Schmitt)</managingEditor><generator>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/IObservable" /><feedburner:info uri="iobservable" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-4675838491237472505</guid><pubDate>Thu, 09 Sep 2010 02:06:00 +0000</pubDate><atom:updated>2010-09-08T22:06:38.755-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Productivity</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><category domain="http://www.blogger.com/atom/ns#">Layout</category><title>Save and Change Tool Layout in Visual Studio</title><description>&lt;p&gt;There have been many people who have asked for a way to save window positions within Visual Studio. For example they layout all their tool windows in a particular order and wish to change it based on the task at hand, but want to get back to the original setup. &lt;p&gt;Previously when asked, I recommended an old &lt;a href="http://vswindowmanager.codeplex.com/" target="_blank"&gt;add-in&lt;/a&gt; and always suggested they update the code for 2008. I got tired of that recommendation, I needed the ability, and I needed it in 2010.&lt;br&gt;So I wrote the following macro to allow a developer to Save, Switch, and Delete window/tool positions within Visual Studio.  &lt;p&gt;The Macros names are pretty self-describing but here is a screenshot of it in action:  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_97nQwcNfnvg/TIhBLPdKgUI/AAAAAAAAAW4/HKYcCR4CLG8/s1600-h/image6%5B1%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh3.ggpht.com/_97nQwcNfnvg/TIhBLr0snjI/AAAAAAAAAW8/x6qx_kpHzoU/image6_thumb.png?imgmax=800" width="422" height="241"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;As always if you want to bind it to a keyboard shortcut go to Tools--&amp;gt;Options--&amp;gt;Environment—&amp;gt;Keyboard. Then in the ‘show commands containing’ box type one of the following: SwitchCurrentView, SaveCurrentView, DeleteSavedView and bind to a shortcut key. (Try - CTRL+ALT+0)  &lt;p&gt;Tested on VS2008 and VS2010 should work in VS2005  &lt;p&gt;Create a new macro module called ‘View’ and paste in the following: (You may need to add a reference to System.Drawing) &lt;pre class="brush: vb;"&gt;Imports System&lt;br /&gt;Imports EnvDTE&lt;br /&gt;Imports System.Collections.Generic&lt;br /&gt;Imports System.Windows.Forms&lt;br /&gt;&lt;br /&gt;Public Module View&lt;br /&gt;    Sub SaveCurrentView()&lt;br /&gt;        Dim viewName As String&lt;br /&gt;        viewName = InputBox("Name your view:", "Save view layout")&lt;br /&gt;        If Not String.IsNullOrEmpty(viewName) Then&lt;br /&gt;            DTE.WindowConfigurations.Add(viewName)&lt;br /&gt;        End If&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;    Sub SwitchCurrentView()&lt;br /&gt;        Using frm As New frmViewSwitcher&lt;br /&gt;            Dim winptr As WinWrapper = New WinWrapper&lt;br /&gt;            Dim ret As DialogResult&lt;br /&gt;            Try&lt;br /&gt;                ret = frm.ShowDialog(winptr)&lt;br /&gt;                If ret = DialogResult.Cancel Then&lt;br /&gt;                    Exit Sub&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                DTE.WindowConfigurations.Item(frm.SelectedView).Apply()&lt;br /&gt;&lt;br /&gt;            Catch ex As Exception&lt;br /&gt;                MsgBox(ex.Message)&lt;br /&gt;            Finally&lt;br /&gt;                ret = Nothing&lt;br /&gt;                winptr = Nothing&lt;br /&gt;            End Try&lt;br /&gt;        End Using&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;    Sub DeleteSavedView()&lt;br /&gt;        Using frm As New frmViewSwitcher&lt;br /&gt;            frm.Name = "Delete View"&lt;br /&gt;            Dim winptr As WinWrapper = New WinWrapper&lt;br /&gt;            Dim ret As DialogResult&lt;br /&gt;            Try&lt;br /&gt;                ret = frm.ShowDialog(winptr)&lt;br /&gt;                If ret = DialogResult.Cancel Then&lt;br /&gt;                    Exit Sub&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;                Dim currentView As String = DTE.WindowConfigurations.ActiveConfigurationName&lt;br /&gt;                Dim selectedView As String = frm.SelectedView&lt;br /&gt;                If Not String.Compare(currentView, selectedView, True) = 0 Then&lt;br /&gt;                    Dim conf As WindowConfiguration = DTE.WindowConfigurations.Item(frm.SelectedView)&lt;br /&gt;                    conf.Delete()&lt;br /&gt;                Else&lt;br /&gt;                    MsgBox("Cannot delete current view!", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Current View")&lt;br /&gt;                End If&lt;br /&gt;&lt;br /&gt;            Catch ex As Exception&lt;br /&gt;                MsgBox(ex.Message)&lt;br /&gt;            Finally&lt;br /&gt;                ret = Nothing&lt;br /&gt;                winptr = Nothing&lt;br /&gt;            End Try&lt;br /&gt;        End Using&lt;br /&gt;    End Sub&lt;br /&gt;End Module&lt;br /&gt;&lt;br /&gt;Partial Class frmViewSwitcher&lt;br /&gt;    Inherits System.Windows.Forms.Form&lt;br /&gt;    Implements IDisposable&lt;br /&gt;&lt;br /&gt;    Private _viewList As List(Of String)&lt;br /&gt;&lt;br /&gt;    Public Sub New()&lt;br /&gt;        InitializeComponent()&lt;br /&gt;&lt;br /&gt;        _viewList = GetViews()&lt;br /&gt;        _viewList.Sort()&lt;br /&gt;&lt;br /&gt;        For Each v As String In _viewList&lt;br /&gt;            lstResults.Items.Add(v)&lt;br /&gt;        Next&lt;br /&gt;        lstResults.Items(0).Selected = True&lt;br /&gt;        Me.Focus()&lt;br /&gt;&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;    WriteOnly Property Name() As String&lt;br /&gt;        Set(ByVal value As String)&lt;br /&gt;            Me.Text = value&lt;br /&gt;        End Set&lt;br /&gt;    End Property&lt;br /&gt;&lt;br /&gt;    Private Function GetViews() As List(Of String)&lt;br /&gt;        Dim rtnList As New List(Of String)&lt;br /&gt;        For Each wc As WindowConfiguration In DTE.WindowConfigurations&lt;br /&gt;            Dim viewName As String = wc.Name&lt;br /&gt;            rtnList.Add(viewName)&lt;br /&gt;        Next&lt;br /&gt;&lt;br /&gt;        Return rtnList&lt;br /&gt;    End Function&lt;br /&gt;&lt;br /&gt;    Public ReadOnly Property SelectedView() As String&lt;br /&gt;        Get&lt;br /&gt;            Return lstResults.SelectedItems(0).Text&lt;br /&gt;        End Get&lt;br /&gt;    End Property&lt;br /&gt;&lt;br /&gt;    Protected Overrides Sub Dispose(ByVal disposing As Boolean)&lt;br /&gt;        Try&lt;br /&gt;            If disposing AndAlso components IsNot Nothing Then&lt;br /&gt;                components.Dispose()&lt;br /&gt;            End If&lt;br /&gt;        Finally&lt;br /&gt;            MyBase.Dispose(disposing)&lt;br /&gt;        End Try&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;    Private Const ControlWidth As Int16 = 400&lt;br /&gt;    Private Const ListHeight As Int16 = 200&lt;br /&gt;    Private Const Padding As Int16 = 5&lt;br /&gt;    Private Const WindowHeight As Int16 = Padding + ListHeight + Padding&lt;br /&gt;    Private Const WindowWidth As Int16 = Padding + ControlWidth + Padding&lt;br /&gt;&lt;br /&gt;    Private components As System.ComponentModel.IContainer&lt;br /&gt;    Private Sub InitializeComponent()&lt;br /&gt;        Me.lstResults = New System.Windows.Forms.ListView&lt;br /&gt;        Me.colViewName = New System.Windows.Forms.ColumnHeader&lt;br /&gt;        Me.colViewName.Text = "View Name"&lt;br /&gt;        Me.button = New System.Windows.Forms.Button&lt;br /&gt;        Me.SuspendLayout()&lt;br /&gt;&lt;br /&gt;        Me.lstResults.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _&lt;br /&gt;                    Or System.Windows.Forms.AnchorStyles.Left) _&lt;br /&gt;                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)&lt;br /&gt;        Me.lstResults.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.colViewName})&lt;br /&gt;        Me.lstResults.FullRowSelect = True&lt;br /&gt;        Me.lstResults.HideSelection = False&lt;br /&gt;        Me.lstResults.Location = New System.Drawing.Point(Padding, Padding)&lt;br /&gt;        Me.lstResults.MultiSelect = False&lt;br /&gt;        Me.lstResults.Name = "lstResults"&lt;br /&gt;        Me.lstResults.Size = New System.Drawing.Size(ControlWidth, ListHeight)&lt;br /&gt;        Me.lstResults.TabIndex = 1&lt;br /&gt;        Me.lstResults.UseCompatibleStateImageBehavior = False&lt;br /&gt;        Me.lstResults.View = System.Windows.Forms.View.Details&lt;br /&gt;&lt;br /&gt;        Me.colViewName.Width = CInt(lstResults.Width - 10)&lt;br /&gt;&lt;br /&gt;        Me.button.DialogResult = System.Windows.Forms.DialogResult.Cancel&lt;br /&gt;        Me.button.Size = New System.Drawing.Size(1, 1)&lt;br /&gt;&lt;br /&gt;        Me.AllowDrop = False&lt;br /&gt;        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)&lt;br /&gt;        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font&lt;br /&gt;        Me.ClientSize = New System.Drawing.Size(WindowWidth, WindowHeight)&lt;br /&gt;        Me.Controls.Add(Me.lstResults)&lt;br /&gt;        Me.Controls.Add(Me.button)&lt;br /&gt;        Me.CancelButton = Me.button&lt;br /&gt;        Me.MaximizeBox = False&lt;br /&gt;        Me.MinimizeBox = False&lt;br /&gt;        Me.Name = "View Switcher"&lt;br /&gt;        Me.ShowIcon = False&lt;br /&gt;        Me.ShowInTaskbar = False&lt;br /&gt;        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen&lt;br /&gt;        Me.Text = "View Switcher"&lt;br /&gt;        Me.ResumeLayout(False)&lt;br /&gt;        Me.PerformLayout()&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;    Friend WithEvents lstResults As System.Windows.Forms.ListView&lt;br /&gt;    Friend WithEvents colViewName As System.Windows.Forms.ColumnHeader&lt;br /&gt;    Friend WithEvents button As System.Windows.Forms.Button&lt;br /&gt;&lt;br /&gt;    Private Sub lstResults_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstResults.DoubleClick&lt;br /&gt;        Me.DialogResult = System.Windows.Forms.DialogResult.OK&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;    Private Sub lstResults_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstResults.KeyUp&lt;br /&gt;        If e.KeyCode = Keys.Enter Then Me.DialogResult = System.Windows.Forms.DialogResult.OK&lt;br /&gt;    End Sub&lt;br /&gt;&lt;br /&gt;End Class&lt;br /&gt;&lt;br /&gt;Public Class WinWrapper&lt;br /&gt;    Implements System.Windows.Forms.IWin32Window&lt;br /&gt;&lt;br /&gt;    Overridable ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle&lt;br /&gt;        Get&lt;br /&gt;            Dim iptr As New System.IntPtr(DTE.MainWindow.HWnd)&lt;br /&gt;            Return iptr&lt;br /&gt;        End Get&lt;br /&gt;    End Property&lt;br /&gt;End Class&lt;br /&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-4675838491237472505?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/fk2iQYKstD0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/fk2iQYKstD0/save-and-change-tool-layout-in-visual.html</link><author>noreply@blogger.com (Brian Schmitt)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_97nQwcNfnvg/TIhBLr0snjI/AAAAAAAAAW8/x6qx_kpHzoU/s72-c/image6_thumb.png?imgmax=800" height="72" width="72" /><thr:total>6</thr:total><feedburner:origLink>http://www.brianschmitt.com/2010/09/save-and-change-tool-layout-in-visual.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-4889721870209620429</guid><pubDate>Tue, 10 Aug 2010 00:38:00 +0000</pubDate><atom:updated>2010-08-09T20:42:24.944-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Converting a concatenated String into String.Format</title><description>&lt;p&gt;So tonight I was browsing unanswered questions on &lt;a href="http://StackOverflow.com" target="_blank"&gt;StackOverflow.com&lt;/a&gt; and I came across a &lt;a href="http://stackoverflow.com/questions/3352779/vs-macro-add-in-to-convert-string-concatenations-to-string-format-style" target="_blank"&gt;question&lt;/a&gt; for which I had written a solution long ago and thought I would turn it into a blog-post instead.&lt;/p&gt; &lt;p&gt;The macro’s purpose is simple - turn a string that you are concatenating into a String.Format statement. This generally produces much more readable code and becomes more maintainable long term. It even attempts to recognize when you are already using a &lt;a href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx" target="_blank"&gt;formatted&lt;/a&gt; ToString.&lt;/p&gt; &lt;p&gt;I have tested with both C# and VB code, Visual Studio 2010 and 2008. To use Highlight the text you want to convert and invoke the macro, I would recommend that you bind it to a keystroke for quick use later on.&lt;/p&gt; &lt;p&gt;For example this:&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;var name = "Brian Schmitt";&lt;br /&gt;Console.WriteLine("Hello " + name);&lt;br /&gt;var money = 1234567.89;&lt;br /&gt;Console.WriteLine("You have " + money.ToString("c") + " dollars");&lt;br /&gt;&lt;br /&gt;var action = "Pay";&lt;br /&gt;var util = "Electric";&lt;br /&gt;Console.WriteLine("Would you like to " + action + " your " + util + " Bill");&lt;br /&gt;Console.ReadLine();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Becomes this:&lt;pre class="brush: csharp;"&gt;var name = "Brian Schmitt";&lt;br /&gt;Console.WriteLine(string.Format("Hello {0}", name));&lt;br /&gt;var money = 1234567.89;&lt;br /&gt;Console.WriteLine(string.Format("You have {0:c} dollars", money));&lt;br /&gt;&lt;br /&gt;var action = "Pay";&lt;br /&gt;var util = "Electric";&lt;br /&gt;Console.WriteLine(string.Format("Would you like to {0} your {1} Bill", action, util));&lt;br /&gt;Console.ReadLine();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt; Finally the Macro:&lt;/p&gt;&lt;pre class="brush: vb;"&gt;Public Sub ConvertToStringFormat()&lt;br /&gt;    DTE.UndoContext.Open("ConvertToStringFormat")&lt;br /&gt;    Dim textSelection As TextSelection = DTE.ActiveDocument.Selection&lt;br /&gt;    Dim output As String = "string.Format(""{0}"", {1})"&lt;br /&gt;    Dim delimt As String = ", "&lt;br /&gt;    Dim fmtdTostring As String = ".tostring("""&lt;br /&gt;&lt;br /&gt;    Dim txtSelection As String() = System.Text.RegularExpressions.Regex.Split(textSelection.Text.Trim, "\+\s_[+\n\r\t]|&amp;amp;\s_[+\n\r\t]|\+|&amp;amp;")&lt;br /&gt;    Dim hardStrings As String = String.Empty&lt;br /&gt;    Dim valueStrings As String = String.Empty&lt;br /&gt;    Dim counter As Int16 = 0&lt;br /&gt;&lt;br /&gt;    For Each str As String In txtSelection&lt;br /&gt;        Dim tmpString As String = str.Trim&lt;br /&gt;        If tmpString.StartsWith("""") Then&lt;br /&gt;            hardStrings &amp;amp;= tmpString.Substring(1, tmpString.Length - 2)&lt;br /&gt;        Else&lt;br /&gt;            Dim fmt As String = String.Empty&lt;br /&gt;            Dim indxToString As Int32 = 0&lt;br /&gt;&lt;br /&gt;            If tmpString.ToLower.Contains(fmtdTostring) Then&lt;br /&gt;                indxToString = tmpString.ToLower.IndexOf(fmtdTostring)&lt;br /&gt;                fmt = tmpString.Substring(indxToString + 11, tmpString.Length - tmpString.ToLower.IndexOf(""")", indxToString) - 1)&lt;br /&gt;            End If&lt;br /&gt;&lt;br /&gt;            If fmt &amp;lt;&amp;gt; String.Empty Then&lt;br /&gt;                hardStrings &amp;amp;= "{" &amp;amp; counter.ToString &amp;amp; ":" &amp;amp; fmt &amp;amp; "}"&lt;br /&gt;                valueStrings &amp;amp;= tmpString.Substring(0, indxToString) &amp;amp; delimt&lt;br /&gt;            Else&lt;br /&gt;                hardStrings &amp;amp;= "{" &amp;amp; counter.ToString &amp;amp; "}"&lt;br /&gt;                valueStrings &amp;amp;= tmpString &amp;amp; delimt&lt;br /&gt;            End If&lt;br /&gt;&lt;br /&gt;            counter += 1&lt;br /&gt;        End If&lt;br /&gt;    Next&lt;br /&gt;&lt;br /&gt;    If valueStrings &amp;lt;&amp;gt; String.Empty Then valueStrings = valueStrings.Substring(0, valueStrings.Length - delimt.Length)&lt;br /&gt;&lt;br /&gt;    textSelection.Text = String.Format(output, hardStrings, valueStrings)&lt;br /&gt;    DTE.UndoContext.Close()&lt;br /&gt;&lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-4889721870209620429?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/wzdY2nUGaWY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/wzdY2nUGaWY/converting-concatenated-string-into.html</link><author>noreply@blogger.com (Brian Schmitt)</author><thr:total>2</thr:total><feedburner:origLink>http://www.brianschmitt.com/2010/08/converting-concatenated-string-into.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-2985768623830522510</guid><pubDate>Mon, 19 Apr 2010 01:51:00 +0000</pubDate><atom:updated>2010-04-18T21:51:57.384-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Hide Selection in 2010, 2008 and 2005</title><description>&lt;p&gt;Visual Studio 2010 is now out and I thought I would share a quick tip that I find useful. This shortcut can be found under Edit—&amp;gt; Outlining –&amp;gt; Hide Selection, and is bound by default to the hot key of CTRL+M, CTRL+H. &lt;/p&gt;  &lt;p&gt;The usefulness of this feature shines when working on large blocks of code, you can highlight any portion of code, apply the Hide Selection option, and the code will ‘Fold’ out of sight - allowing you to focus just on the portion you are interested in. This information is stored in your .suo file, so other members of the team are not affected and will be persisted to future sessions. I have found this to work in all types of source files: .aspx, .cs, .vb, .css, and many others.&lt;/p&gt;  &lt;p&gt;This relatively little known feature was in previous versions of Visual Studio, but became broken after 2005 SP1. Jay Flowers even wrote a &lt;a href="http://jayflowers.com/WordPress/?p=134"&gt;CodeRush plugin&lt;/a&gt; to accomplish the same thing. &lt;/p&gt;  &lt;p&gt;If you are still on 2005/2008 and would like to have this feature now I provide to you the following macro:&lt;/p&gt;  &lt;pre class="brush: vb;"&gt;Sub FoldCode()&lt;br /&gt;    Dim selection As TextSelection = DTE.ActiveDocument.Selection&lt;br /&gt;    selection.OutlineSection()&lt;br /&gt;End Sub&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-2985768623830522510?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/kWb1lVn5ZJU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/kWb1lVn5ZJU/hide-selection-in-2010-2008-and-2005.html</link><author>noreply@blogger.com (Brian Schmitt)</author><thr:total>0</thr:total><feedburner:origLink>http://www.brianschmitt.com/2010/04/hide-selection-in-2010-2008-and-2005.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-6984203208168081448</guid><pubDate>Thu, 14 Jan 2010 03:03:00 +0000</pubDate><atom:updated>2010-01-13T22:07:01.783-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Regex</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Remove Visual Studio Regions with Find and Replace</title><description>&lt;p&gt;Recently Uncle Bob was talking on twitter about &lt;a href="http://twitter.com/unclebobmartin/status/7676319628"&gt;regions&lt;/a&gt;. He says &amp;quot;Purge All Regions&amp;quot; - Well today's snippet is going to do just that. &lt;/p&gt;  &lt;p&gt;The inspiration for this originated with Kyle Bailey's post from a &lt;a href="http://codebetter.com/blogs/kyle.baley/archive/2007/12/17/removing-regions-or-quot-how-to-keep-your-code-expanded-quot.aspx"&gt;few years ago&lt;/a&gt;. I had taken it, modified it, and today I share it with you; it can be used as a macro as Kyle created it, or you can use it right in Visual Studio’s Find and Replace.&lt;/p&gt;  &lt;p&gt;Every developer knows how to use Find and Find/Replace, however I have only found a few that know that you can use regular expressions. The regular expressions that Visual Studio supports in the Find Dialog is a slimed down version and is &lt;a href="http://msdn.microsoft.com/en-us/library/2k3te2cs.aspx"&gt;specific to Visual Studio&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_97nQwcNfnvg/S06JfgtFJcI/AAAAAAAAAV4/tNBAl-XbNZ0/s1600-h/image%5B16%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/S06Jf6lKMFI/AAAAAAAAAV8/6mQaKYcwQ0w/image_thumb%5B6%5D.png?imgmax=800" width="356" height="463" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The following will work in both C# and VB, in the Find Options simply select “Use Regular Expressions” and replace with nothing. Change the Look in option to specify the scope of your search and you can make the change solution wide or just your current file.&lt;/p&gt;  &lt;pre class="brush: plain;"&gt;&lt;br /&gt;&lt;br /&gt;^.*\#(end)*(:Wh)*region.*\n&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Simple, quick and effective! &lt;br /&gt;&lt;br /&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-6984203208168081448?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/G6DYB6rfd70" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/G6DYB6rfd70/clear-visual-studio-regions.html</link><author>noreply@blogger.com (Brian Schmitt)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_97nQwcNfnvg/S06Jf6lKMFI/AAAAAAAAAV8/6mQaKYcwQ0w/s72-c/image_thumb%5B6%5D.png?imgmax=800" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://www.brianschmitt.com/2010/01/clear-visual-studio-regions.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-6627492727572131996</guid><pubDate>Wed, 06 Jan 2010 23:47:00 +0000</pubDate><atom:updated>2010-01-06T18:49:28.789-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Locate File in Solution Explorer – Visual Studio Macro</title><description>&lt;p&gt;Today's Macro is very basic, but I use it almost daily.&lt;/p&gt;  &lt;p&gt;I use a customized IDE and one of the performance tweaks I have performed is to Turn Off the Track Active Items (Tools --&amp;gt; Options --&amp;gt; Projects and Solutions).&lt;/p&gt;  &lt;p&gt;This feature, when enabled, syncs the selected item in your solution explorer to the file being viewed.&lt;/p&gt;  &lt;p&gt;There are times that I have traced down into a file and then needed to locate it in the Solution Explorer; This Macro will assist you finding the current file while leaving the feature turned off.&lt;/p&gt;  &lt;p&gt;(Other add-ins like ReSharper offer a similar feature &amp;quot;Locate in Solution Explorer&amp;quot;)&lt;/p&gt;  &lt;p&gt;About the Macro: The First Command toggles on the feature, the second toggles it back off - this allows Visual Studio to find the item in the solution explorer.&lt;/p&gt;  &lt;p&gt;Then the third line simply causes the solution explorer to be displayed, this works if the solution explorer window is hidden or closed.&lt;/p&gt;  &lt;p&gt;Bind it to a shortcut key and you are all set - mine is bound to (ALT+L, ALT+L)&lt;/p&gt;  &lt;pre class="brush: vb;"&gt;&lt;br /&gt;Public Sub LocateFileInSolutionExplorer() &lt;br /&gt;    DTE.ExecuteCommand(&amp;quot;View.TrackActivityinSolutionExplorer&amp;quot;) &lt;br /&gt;    DTE.ExecuteCommand(&amp;quot;View.TrackActivityinSolutionExplorer&amp;quot;) &lt;br /&gt;    DTE.ExecuteCommand(&amp;quot;View.SolutionExplorer&amp;quot;) &lt;br /&gt;End Sub&lt;br /&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-6627492727572131996?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/quRMD9WuxoM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/quRMD9WuxoM/locate-file-in-solution-explorer-visual.html</link><author>noreply@blogger.com (Brian Schmitt)</author><thr:total>3</thr:total><feedburner:origLink>http://www.brianschmitt.com/2010/01/locate-file-in-solution-explorer-visual.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-3547776483354413217</guid><pubDate>Wed, 21 Oct 2009 01:51:00 +0000</pubDate><atom:updated>2009-10-29T09:23:41.555-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Fixing the Visual Studio Add Reference Dialog – Quickly add a Project Reference</title><description>&lt;p&gt;Today's macro addresses one of the most common complaints about Visual Studio - The &amp;quot;Add Reference&amp;quot; dialog - I will help you speed it up when you only need to add a project reference.&lt;/p&gt;  &lt;p&gt;I know the issue is fixed in the latest beta of 2010 but I provide this here for those who are still using 2008 or lower.&lt;/p&gt;  &lt;p&gt;I know we have all been there at one time or another – you add a new class library and want to add a reference in your UI to the project – but we dread the dialog box to add that reference - Will today be a lucky day and it only take 30 seconds to load? With this macro you can quickly add a reference to another project in the same solution. It offers a simple dialog box for you to choose one or more projects. Hope you find it just as useful as I do. &lt;a href="http://weblogs.asp.net/kdente/"&gt;Kevin Dente&lt;/a&gt; had a great suggestion that the add reference dialog should support filtering/searching – This is possible and I’ll see what I can do about it.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_97nQwcNfnvg/St5o4ha712I/AAAAAAAAAUo/VueonusbwOo/s1600-h/image%5B19%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/St5o6-Raw0I/AAAAAAAAAUs/5ND_60shi_A/image_thumb%5B9%5D.png?imgmax=800" width="298" height="326" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Here is the code: (Scroll down for instructions on how you can add it to your context menu)&lt;/p&gt;  &lt;pre class="brush: vb;"&gt;Imports System&lt;br /&gt;Imports EnvDTE&lt;br /&gt;Imports EnvDTE80&lt;br /&gt;Imports EnvDTE90&lt;br /&gt;Imports System.Diagnostics&lt;br /&gt;Imports System.Windows.Forms&lt;br /&gt;Imports System.Collections&lt;br /&gt; &lt;br /&gt;Public Module References&lt;br /&gt;    Public Sub AddProjectReference()&lt;br /&gt;        Dim frm As New SelectProjectForm&lt;br /&gt;        Dim winptr As WinWrapper = New WinWrapper&lt;br /&gt;        Try&lt;br /&gt;            Dim ret As DialogResult = frm.ShowDialog(winptr)&lt;br /&gt;            If ret = DialogResult.Cancel Then&lt;br /&gt;                Return&lt;br /&gt;            End If&lt;br /&gt; &lt;br /&gt;            Dim actvProjs As Array = DTE.ActiveSolutionProjects()&lt;br /&gt;            Dim sngProj As Project = CType(actvProjs.GetValue(0), EnvDTE.Project)&lt;br /&gt;            Dim vsProj As VSLangProj.VSProject = DirectCast(sngProj.Object, VSLangProj.VSProject)&lt;br /&gt; &lt;br /&gt;            For Each proj As Project In frm.SelectedProjects&lt;br /&gt;                Try&lt;br /&gt;                    vsProj.References.AddProject(proj)&lt;br /&gt;                Catch ex As Exception&lt;br /&gt;                    MsgBox(ex.Message, MsgBoxStyle.Critical And MsgBoxStyle.OkOnly, &amp;quot;Error - &amp;quot; &amp;amp; proj.Name)&lt;br /&gt;                End Try&lt;br /&gt;            Next&lt;br /&gt;        Finally&lt;br /&gt;            frm = Nothing&lt;br /&gt;            winptr = Nothing&lt;br /&gt;        End Try&lt;br /&gt;    End Sub&lt;br /&gt; &lt;br /&gt;    Private Class SelectProjectForm&lt;br /&gt;        Inherits System.Windows.Forms.Form&lt;br /&gt; &lt;br /&gt;        Public Sub New()&lt;br /&gt;            InitializeComponent()&lt;br /&gt; &lt;br /&gt;            lstProjects.DisplayMember = &amp;quot;Name&amp;quot;&lt;br /&gt;            lstProjects.DataSource = GetAllProjects()&lt;br /&gt;            lstProjects.Select()&lt;br /&gt;        End Sub&lt;br /&gt; &lt;br /&gt;        Public ReadOnly Property SelectedProjects() As Generic.List(Of Project)&lt;br /&gt;            Get&lt;br /&gt;                Dim lst As New Generic.List(Of Project)&lt;br /&gt;                For Each itm As Object In lstProjects.SelectedItems&lt;br /&gt;                    lst.Add(CType(itm, Project))&lt;br /&gt;                Next&lt;br /&gt;                Return lst&lt;br /&gt;            End Get&lt;br /&gt;        End Property&lt;br /&gt; &lt;br /&gt;        Private Function GetAllProjects() As Generic.List(Of Project)&lt;br /&gt;            Dim lst As New Generic.List(Of Project)&lt;br /&gt;            For Each proj As Project In DTE.Solution.Projects&lt;br /&gt;                If proj.Kind = Constants.vsProjectKindSolutionItems Then&lt;br /&gt;                    lst.AddRange(GetSubProjects(proj.ProjectItems))&lt;br /&gt;                Else&lt;br /&gt;                    lst.Add(proj)&lt;br /&gt;                End If&lt;br /&gt;            Next&lt;br /&gt;            Return lst&lt;br /&gt;        End Function&lt;br /&gt;&lt;br /&gt;        Private Function GetSubProjects(ByVal pis As ProjectItems) As Generic.List(Of Project)&lt;br /&gt;            Dim lst As New Generic.List(Of Project)&lt;br /&gt;            For Each pi As ProjectItem In pis&lt;br /&gt;                If pi.Kind = Constants.vsProjectItemKindSolutionItems Then&lt;br /&gt;                    lst.Add(pi.SubProject)&lt;br /&gt;                ElseIf pi.Kind = Constants.vsProjectKindSolutionItems Then&lt;br /&gt;                    lst.AddRange(GetSubProjects(pi.ProjectItems))&lt;br /&gt;                End If&lt;br /&gt;            Next&lt;br /&gt;            Return lst&lt;br /&gt;        End Function&lt;br /&gt; &lt;br /&gt;        Private Sub InitializeComponent()&lt;br /&gt;            Me.btnOk = New System.Windows.Forms.Button&lt;br /&gt;            Me.btnCancel = New System.Windows.Forms.Button&lt;br /&gt;            Me.lstProjects = New System.Windows.Forms.ListBox&lt;br /&gt;            Me.SuspendLayout()&lt;br /&gt; &lt;br /&gt;            Me.btnOk.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)&lt;br /&gt;            Me.btnOk.Location = New System.Drawing.Point(197, 230)&lt;br /&gt;            Me.btnOk.Name = &amp;quot;btnOk&amp;quot;&lt;br /&gt;            Me.btnOk.Size = New System.Drawing.Size(75, 23)&lt;br /&gt;            Me.btnOk.TabIndex = 1&lt;br /&gt;            Me.btnOk.Text = &amp;quot;Ok&amp;quot;&lt;br /&gt;            Me.btnOk.UseVisualStyleBackColor = True&lt;br /&gt; &lt;br /&gt;            Me.btnCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)&lt;br /&gt;            Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel&lt;br /&gt;            Me.btnCancel.Location = New System.Drawing.Point(116, 231)&lt;br /&gt;            Me.btnCancel.Name = &amp;quot;btnCancel&amp;quot;&lt;br /&gt;            Me.btnCancel.Size = New System.Drawing.Size(75, 23)&lt;br /&gt;            Me.btnCancel.TabIndex = 2&lt;br /&gt;            Me.btnCancel.Text = &amp;quot;Cancel&amp;quot;&lt;br /&gt;            Me.btnCancel.UseVisualStyleBackColor = True&lt;br /&gt; &lt;br /&gt;            Me.lstProjects.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _&lt;br /&gt;                        Or System.Windows.Forms.AnchorStyles.Left) _&lt;br /&gt;                        Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)&lt;br /&gt;            Me.lstProjects.FormattingEnabled = True&lt;br /&gt;            Me.lstProjects.Location = New System.Drawing.Point(13, 13)&lt;br /&gt;            Me.lstProjects.Name = &amp;quot;lstProjects&amp;quot;&lt;br /&gt;            Me.lstProjects.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended&lt;br /&gt;            Me.lstProjects.Size = New System.Drawing.Size(259, 212)&lt;br /&gt;            Me.lstProjects.TabIndex = 3&lt;br /&gt; &lt;br /&gt;            Me.AcceptButton = Me.btnOk&lt;br /&gt;            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)&lt;br /&gt;            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font&lt;br /&gt;            Me.CancelButton = Me.btnCancel&lt;br /&gt;            Me.ClientSize = New System.Drawing.Size(284, 262)&lt;br /&gt;            Me.Controls.Add(Me.lstProjects)&lt;br /&gt;            Me.Controls.Add(Me.btnCancel)&lt;br /&gt;            Me.Controls.Add(Me.btnOk)&lt;br /&gt;            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow&lt;br /&gt;            Me.Name = &amp;quot;Form1&amp;quot;&lt;br /&gt;            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent&lt;br /&gt;            Me.Text = &amp;quot;Select Project(s)&amp;quot;&lt;br /&gt;            Me.ResumeLayout(False)&lt;br /&gt;        End Sub&lt;br /&gt;        Friend WithEvents lstProjects As System.Windows.Forms.ListBox&lt;br /&gt;        Friend WithEvents btnOk As System.Windows.Forms.Button&lt;br /&gt;        Friend WithEvents btnCancel As System.Windows.Forms.Button&lt;br /&gt; &lt;br /&gt;        Private Sub lstProjects_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstProjects.DoubleClick&lt;br /&gt;            Me.DialogResult = System.Windows.Forms.DialogResult.OK&lt;br /&gt;        End Sub&lt;br /&gt; &lt;br /&gt;        Private Sub lstProjects_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lstProjects.KeyUp&lt;br /&gt;            If e.KeyCode = Keys.Enter Then Me.DialogResult = System.Windows.Forms.DialogResult.OK&lt;br /&gt;        End Sub&lt;br /&gt; &lt;br /&gt;        Private Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click&lt;br /&gt;            Me.DialogResult = System.Windows.Forms.DialogResult.OK&lt;br /&gt;        End Sub&lt;br /&gt;    End Class&lt;br /&gt; &lt;br /&gt;End Module&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;For those who would like to add the macro (or any macro) to your right click context menu follow these steps:&lt;/p&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Right Click on Menu Bar &lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Choose Customize at bottom &lt;/li&gt;&lt;br /&gt;  &lt;li&gt;In the list choose &amp;quot;Context Menus&amp;quot; - Choose the Commands tab &lt;a href="http://lh4.ggpht.com/_97nQwcNfnvg/St5o8FcNUvI/AAAAAAAAAUw/xsAooKAEoLk/s1600-h/image%5B7%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/St5o9mkbzJI/AAAAAAAAAU0/APDg47l0lvo/image_thumb%5B3%5D.png?imgmax=800" width="527" height="418" /&gt;&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;  &lt;li&gt;In the categories choose Macros and then locate your new macro &lt;a href="http://lh4.ggpht.com/_97nQwcNfnvg/St5o-94KmFI/AAAAAAAAAU4/hncdSpx7LGs/s1600-h/image%5B11%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/St5o_y7iEuI/AAAAAAAAAU8/U6cUlVyf5T0/image_thumb%5B5%5D.png?imgmax=800" width="509" height="124" /&gt;&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Drag it up to the context menu bar that appeared when you selected it above, &lt;br /&gt;    &lt;br /&gt;hover over Project and Solution Context Menus, Project and then Drop it under Add Reference. &lt;a href="http://lh3.ggpht.com/_97nQwcNfnvg/St5pBQinksI/AAAAAAAAAVA/sjpAnrocOx0/s1600-h/image%5B15%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/St5pD8XaQBI/AAAAAAAAAVE/cRo4gADe1zU/image_thumb%5B7%5D.png?imgmax=800" width="462" height="494" /&gt;&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;  &lt;li&gt;Give it a friendly name. This will make it available when you right click on a project file in solution explorer&amp;#160; &lt;a href="http://lh4.ggpht.com/_97nQwcNfnvg/St5o4ha712I/AAAAAAAAAUo/VueonusbwOo/s1600-h/image%5B19%5D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/St5o6-Raw0I/AAAAAAAAAUs/5ND_60shi_A/image_thumb%5B9%5D.png?imgmax=800" width="298" height="326" /&gt;&lt;/a&gt; &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-3547776483354413217?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/3_UUkiv2pUg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/3_UUkiv2pUg/fixing-visual-studio-add-reference.html</link><author>noreply@blogger.com (Brian Schmitt)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_97nQwcNfnvg/St5o6-Raw0I/AAAAAAAAAUs/5ND_60shi_A/s72-c/image_thumb%5B9%5D.png?imgmax=800" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://www.brianschmitt.com/2009/10/fixing-visual-studio-add-reference.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-129591872168067653</guid><pubDate>Fri, 11 Sep 2009 18:52:00 +0000</pubDate><atom:updated>2009-09-11T14:58:55.869-04:00</atom:updated><title>How to Comment-Uncomment Code Selection in Style Sheets - (or How to fix Visual Studio's broken implementation)</title><description>&lt;p&gt;If you commonly comment out portions of code, then you are used to highlighting a portion of text and using the shortcut of CTRL+K, CTRL+C (or the toolbar) to comment out the selected text. &lt;/p&gt;  &lt;p&gt;While this will work for most source files, it does not currently work inside Visual Studio for style sheets (.css) files. (See screenshot and note the status bar message)&lt;/p&gt;  &lt;p&gt;&lt;img title="Comment Selection not currently available" style="border-width: 0px; display: inline;" alt="Comment Selection not currently available" src="http://lh3.ggpht.com/_97nQwcNfnvg/SqqcdcdHuqI/AAAAAAAAAUU/wntoRcM9eXY/clip_image002_thumb%5B2%5D.jpg?imgmax=800" border="0" height="140" width="458" /&gt;&lt;/p&gt;  &lt;p&gt;Why Microsoft has left out this basic functionality is beyond me; In this post, I would like to demonstrate how you can write your own macro to fix it. &lt;/p&gt;  &lt;p&gt;First we will record a basic macro - later we will modify it to suit our needs.&lt;/p&gt;  &lt;p&gt;&lt;img title="record temporary macro" style="border-width: 0px; display: inline;" alt="record temporary macro" src="http://lh6.ggpht.com/_97nQwcNfnvg/SqqcdmhVhlI/AAAAAAAAAUY/9dk71iHSDYE/clip_image002%5B6%5D_thumb%5B1%5D.jpg?imgmax=800" border="0" height="202" width="459" /&gt;&lt;/p&gt;  &lt;p&gt;Start out by opening a style sheet and placing your cursor at the relevant piece of code, next start recording by selecting Record TemporaryMacro (Tools--&amp;gt;Macros--&amp;gt;Record... or CTRL+Shift+R). Using the keyboard highlight some style information and Ctrl+X to cut your selection to the clipboard. Next add the beginning of our comment /* and paste your code back in. Lastly add the comment close */ and stop recording your macro. &lt;/p&gt;  &lt;p&gt;&lt;img title="temporarymacro" style="border-width: 0px; display: inline;" alt="temporarymacro" src="http://lh6.ggpht.com/_97nQwcNfnvg/Sqqcd90Mc9I/AAAAAAAAAUc/HpFKQTzJRyY/clip_image002%5B8%5D_thumb.jpg?imgmax=800" border="0" height="132" width="236" /&gt;&lt;/p&gt;  &lt;p&gt;Browse your Macro Explorer and you will notice a "RecordingModule" and if expanded a "Temporary Macro". Right click on the macro and choose edit causing your Macro Editor to open. If you completed the steps outlined above you should have ended up with something roughly similar to this: &lt;/p&gt;&lt;pre class="brush: vb;"&gt;Sub TemporaryMacro()&lt;br /&gt; DTE.ActiveDocument.Selection.LineUp(True, 5)&lt;br /&gt; DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)&lt;br /&gt; DTE.ActiveDocument.Selection.Cut()&lt;br /&gt; DTE.ActiveDocument.Selection.Text = "/*"&lt;br /&gt; DTE.ActiveDocument.Selection.Paste()&lt;br /&gt; DTE.ActiveDocument.Selection.Text = "*/"&lt;br /&gt;End Sub&lt;/pre&gt;&lt;p&gt;You can see that it recorded the exact steps I took: I highlighted five lines, cut the text, typed, pasted and finally typed some more. If you go back to your text editor and undo your changes and run the macro you should end up with the same ending result.&lt;/p&gt;&lt;p&gt;&lt;img title="commented style - css" style="border-width: 0px; display: inline;" alt="commented style - css" src="http://lh4.ggpht.com/_97nQwcNfnvg/SqqceT2MDCI/AAAAAAAAAUg/FqyX85WQm3k/clip_image002%5B12%5D_thumb%5B1%5D.jpg?imgmax=800" border="0" height="179" width="415" /&gt;&lt;/p&gt;&lt;p&gt;As you can see, for repeatable actions, Macros are great - however at this point you might be thinking - What if I want to comment out 3 lines (or 10 or more)?. Now that we have our starting point, we can modify our temporary macro to better accommodate our concerns and match the common VS implementation. &lt;/p&gt;&lt;p&gt;Let's start modifying by simply grabbing the currently selected text, as you can see VS stores this in DTE.ActiveDocument.Selection and then we will append /* and */ to the beginning and end. &lt;/p&gt;&lt;p&gt;So we end up with something like this: &lt;/p&gt;&lt;pre class="brush: vb;"&gt;Sub TemporaryMacro()&lt;br /&gt; Dim txtSel As TextSelection&lt;br /&gt; txtSel = DTE.ActiveDocument.Selection&lt;br /&gt; txtSel.Text = "/*" + txtSel.Text + "*/"&lt;br /&gt;End Sub&lt;/pre&gt;&lt;p&gt;That's a fairly good substitute for our previous recorded macro; We can highlight lines with our mouse or keyboard and execute the macro, and it will comment out a variable number of lines. It works, but could be better. &lt;/p&gt;&lt;p&gt;With the above variation, if you highlight multiple lines and then 'undo' the changes you will notice that it will undo it line by line, a minor annoyance, but luckily the macro system has something just for this scenario. It is called the UndoContext and is fairly easy to use: &lt;/p&gt;&lt;pre class="brush: vb;"&gt;Sub TemporaryMacro()&lt;br /&gt; Try&lt;br /&gt;  DTE.UndoContext.Open("Comment CSS")&lt;br /&gt;  Dim txtSel As TextSelection&lt;br /&gt;  txtSel = DTE.ActiveDocument.Selection&lt;br /&gt;  txtSel.Text = "/*" + txtSel.Text + "*/"&lt;br /&gt; Finally&lt;br /&gt;  DTE.UndoContext.Close()&lt;br /&gt; End Try&lt;br /&gt;End Sub&lt;/pre&gt;&lt;p&gt;You should wrap it in a Try/Finally - This is important, but I won't go into 'why' here. Now highlight multiple lines run the macro and then undo it, your changes are preformed as a single transaction and rolled back as one too. It is a nice little enhancement that will give your final macro some polish. &lt;/p&gt;&lt;p&gt;One final enhancement to our macro, In VS you can Comment and also Uncomment a section of code - that would be a nice feature too. However, instead of writing it as a separate macro, let's detect if the code is currently commented, and if so, uncomment it. In the end we should be able to bind a single shortcut for both comment and uncomment. &lt;/p&gt;&lt;p&gt;Here is our final code: &lt;/p&gt;&lt;pre class="brush: vb;"&gt;Sub CommentCSS()&lt;br /&gt;'Detect if in a CSS file&lt;br /&gt;If Not DTE.ActiveDocument.Name.EndsWith("css") Then Return&lt;br /&gt; Try&lt;br /&gt;  DTE.UndoContext.Open("Comment CSS")&lt;br /&gt;  &lt;br /&gt;  Dim txtSel As TextSelection = DTE.ActiveDocument.Selection&lt;br /&gt;  Dim currText As String = txtSel.Text&lt;br /&gt;&lt;br /&gt;  If currText.Length &amp;gt; 0 Then&lt;br /&gt;   Dim newTxt As String&lt;br /&gt;   If currText.Trim.StartsWith("/*") AndAlso currText.Trim.EndsWith("*/") Then&lt;br /&gt;    newTxt = currText.Replace("/*", "").Replace("*/", "")&lt;br /&gt;   Else&lt;br /&gt;    newTxt = "/*" + currText + "*/"&lt;br /&gt;   End If&lt;br /&gt;   &lt;br /&gt;   txtSel.Delete() 'This is to help keep formatting correct when multiline&lt;br /&gt;   txtSel.Insert(newTxt, vsInsertFlags.vsInsertFlagsInsertAtEnd)&lt;br /&gt;  End If&lt;br /&gt; Finally&lt;br /&gt;  DTE.UndoContext.Close()&lt;br /&gt; End Try&lt;br /&gt;End Sub&lt;/pre&gt;&lt;p&gt;Now to bind our Macro to a keyboard chord: Go to Tools--&amp;gt;Options--&amp;gt;Environment--&amp;gt;Keyboard - In the show commands type CommentCSS, in the dropdown "Use new shortcut in" change the selection to CSS Source Editor, finally in the "Press Shortcut Keys" type CTRL+K, CTRL+C and assign it.&lt;/p&gt;&lt;p&gt;&lt;img title="key binding" style="border-width: 0px; display: inline;" alt="key binding" src="http://lh6.ggpht.com/_97nQwcNfnvg/Sqqcetg5_lI/AAAAAAAAAUk/ASgwppBIKBI/clip_image002%5B10%5D_thumb%5B2%5D.jpg?imgmax=800" border="0" height="364" width="600" /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-129591872168067653?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/KWoeXMnooMc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/KWoeXMnooMc/how-to-comment-uncomment-code-selection.html</link><author>noreply@blogger.com (Brian Schmitt)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_97nQwcNfnvg/SqqcdcdHuqI/AAAAAAAAAUU/wntoRcM9eXY/s72-c/clip_image002_thumb%5B2%5D.jpg?imgmax=800" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://www.brianschmitt.com/2009/09/how-to-comment-uncomment-code-selection.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-906495508292947919</guid><pubDate>Tue, 08 Sep 2009 14:17:00 +0000</pubDate><atom:updated>2009-09-08T10:19:36.492-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Quickly Reformat your Project Files</title><description>&lt;p&gt;Recently on twitter &lt;a href="http://twitter.com/haacked/status/3832509024"&gt;Phil Haacked asked about reformatting the files&lt;/a&gt; in a project where it didn't match his preferences. We have all been there, looking at a file that we downloaded or was given, and would find it easier to follow if we could reformat it. &lt;/p&gt;  &lt;p&gt;There is an often overlooked feature of Visual Studio that will reformat our code for us. I frequently use it on HTML documents to quickly restructure code in View Source. &lt;/p&gt;  &lt;p&gt;This functionality can be found under Edit--&amp;gt;Advanced--&amp;gt;Format Document (or CTRL+K, CTRL+D)  as well as Format Selection – which only applies to the currently highlighted text.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_97nQwcNfnvg/SqZnkTMbwmI/AAAAAAAAAUM/VR5-z8ohMbw/s1600-h/image%5B8%5D.png"&gt;&lt;img title="image" style="border-width: 0px; display: inline;" alt="image" src="http://lh4.ggpht.com/_97nQwcNfnvg/SqZnkpSTM4I/AAAAAAAAAUQ/9TB1cQCQCuw/image_thumb%5B4%5D.png?imgmax=800" border="0" height="144" width="491" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;One thing to mention is that you should define how you want your code formatted by going to Tools--&amp;gt;Options--&amp;gt;Text Editor and then select your language of choice. (Some languages offer a greater degree of customization) &lt;/p&gt;  &lt;p&gt;Now that you know how to reformat a document and how you can define its result, we will write a macro that will achieve what Phil was looking for by - loop through each source file - open, format, save, and then close it:&lt;/p&gt;  &lt;pre class="brush: vb;"&gt;    Sub FormatAll()&lt;br /&gt;       For Each proj As Project In DTE.Solution.Projects&lt;br /&gt;           FormatFileRecur(proj.ProjectItems())&lt;br /&gt;       Next&lt;br /&gt;   End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   Sub FormatFileRecur(ByVal projectItems As EnvDTE.ProjectItems)&lt;br /&gt;       For Each pi As EnvDTE.ProjectItem In projectItems&lt;br /&gt;           If pi.Collection Is projectItems Then&lt;br /&gt;               Dim pi2 As EnvDTE.ProjectItems = pi.ProjectItems&lt;br /&gt;               Try&lt;br /&gt;                   If Not pi.IsOpen Then pi.Open(Constants.vsViewKindCode)&lt;br /&gt;                   pi.Document.Activate()&lt;br /&gt;                   DTE.ExecuteCommand("Edit.FormatDocument")&lt;br /&gt;                   If Not pi.Document.Saved Then pi.Document.Save()&lt;br /&gt;                   pi.Document.Close()&lt;br /&gt;               Catch ex As Exception&lt;br /&gt;                   'Ignore this error - some project items cannot be opened.&lt;br /&gt;               End Try&lt;br /&gt;               If pi2 IsNot Nothing Then&lt;br /&gt;                   FormatFileRecur(pi2)&lt;br /&gt;               End If&lt;br /&gt;           End If&lt;br /&gt;       Next&lt;br /&gt;   End Sub&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-906495508292947919?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/k5F_QTnkAdw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/k5F_QTnkAdw/quickly-reformat-your-project-files.html</link><author>noreply@blogger.com (Brian Schmitt)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_97nQwcNfnvg/SqZnkpSTM4I/AAAAAAAAAUQ/9TB1cQCQCuw/s72-c/image_thumb%5B4%5D.png?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.brianschmitt.com/2009/09/quickly-reformat-your-project-files.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-5160611193952922169</guid><pubDate>Fri, 28 Aug 2009 01:50:00 +0000</pubDate><atom:updated>2009-09-01T22:27:45.357-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Presentations</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><title>Intro to Visual Studio Macros and The Most Important Macro for Presenters</title><description>&lt;p&gt;In my &lt;a href="http://www.brianschmitt.com/2009/08/better-visual-studio-f1.html"&gt;last post&lt;/a&gt; I told you how to use a macro to replace the F1 'Help' functionality to perform a search on the internet.&lt;/p&gt;  &lt;p&gt;In this post, I hope to explain some of the basics of Macros, the single most important macro for presenters/speakers, and how you can bind a macro to a keyboard shortcut.&lt;/p&gt;  &lt;h4&gt;Basics of Macros&lt;/h4&gt;  &lt;p&gt;Visual Studio offers a very rich extensibility model and &lt;strong&gt;you&lt;/strong&gt; can extend and bend it in many ways.&lt;/p&gt;  &lt;p&gt;One way to harness the power of Visual Studio is through macros. A macro has access to some of the core functionality within Visual Studio. An advantage of VS Macros is that you do not have to install or compile them. Sharing is very simple as its just plaintext; You simply need the relative snippet of code and paste it in.&lt;/p&gt;  &lt;p&gt;I feel that one of the hardest things about Macros is discovering they are available and beginning to use them.&lt;/p&gt;  &lt;p&gt;So, lets get started with running a Macro, in Visual Studio hit Alt+F8, this will open your Macro Explorer. It is very much like a Solution Explorer for your Macros. It is here that you can select and run your macros. We will be taking a look at the samples already included with your install of Visual Studio.&lt;/p&gt; &lt;br /&gt;&lt;h4&gt;Single Most Important Macro for Presenters&lt;/h4&gt;  &lt;p&gt;Expand the Samples and then expand Accessibility, you should see several macros there, and for this exercise we are interested in DecreaseTextEditorFontSize and &lt;strong&gt;IncreaseTextEditorFontSize&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_97nQwcNfnvg/Spc32AJUyCI/AAAAAAAAAT8/eYszIKIbJU0/s1600-h/Picture%20%28Device%20Independent%20Bitmap%29%201%5B3%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="Macro Explorer" alt="Macro Explorer" src="http://lh3.ggpht.com/_97nQwcNfnvg/Spc32XnSGOI/AAAAAAAAAUA/_fJgtrjbsFU/Picture%20%28Device%20Independent%20Bitmap%29%201_thumb%5B1%5D.jpg?imgmax=800" border="0" height="285" width="283" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Double Click to run one of them, if you have a file open in your editor you should notice the size of the font has now changed. Now Double click and run the opposite macro, and it should switch back to the size you had.&lt;/p&gt;  &lt;p&gt;If you are a presenter you can and should definitely know about these two macros! They will allow you to quickly change your environment suitable for an audience.&lt;/p&gt;  &lt;p&gt;If you would like to see the code at accomplished this feat, right click on the macro and choose edit, this will open up the Macro Editor, it's a stripped down version of your standard Visual Studio Editor, but you should feel comfortable using it.&lt;/p&gt;  &lt;p&gt;For those not sitting at your IDE here is the relevant code:&lt;/p&gt;  &lt;pre class="brush: vb;"&gt;' Increases the font size used within the editor.&lt;br /&gt;Public Sub IncreaseTextEditorFontSize()&lt;br /&gt;   Dim textEditorFontsAndColors As Properties&lt;br /&gt;   textEditorFontsAndColors = DTE.Properties("FontsAndColors", "TextEditor")&lt;br /&gt;   textEditorFontsAndColors.Item("FontSize").Value += fontSizeIncrement&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;' Decreases the font size used within the editor.&lt;br /&gt;Public Sub DecreaseTextEditorFontSize()&lt;br /&gt;   Dim textEditorFontsAndColors As Properties&lt;br /&gt;   Dim fontSize As [Property]&lt;br /&gt;&lt;br /&gt;   textEditorFontsAndColors = DTE.Properties("FontsAndColors", "TextEditor")&lt;br /&gt;   fontSize = textEditorFontsAndColors.Item("FontSize")&lt;br /&gt;&lt;br /&gt;   If fontSize.Value &amp;gt;= minimumSupportedEditorSize Then&lt;br /&gt;       fontSize.Value -= fontSizeIncrement&lt;br /&gt;   End If&lt;br /&gt;End Sub&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The two methods simply take the current font size and increment it by a defined amount.&lt;/p&gt;&lt;p&gt;See how simple, yet powerful macros can be?  I know, I know - increasing a font size is not &lt;em&gt;that&lt;/em&gt; powerful, but this sample shows that you can tap into key places and accomplish repetitive, mundane tasks. I will show more powerful samples in the future.&lt;/p&gt;&lt;br /&gt;&lt;h4&gt;Key Binding&lt;/h4&gt;&lt;p&gt;As one final exercise lets bind a macro to a keyboard shortcut.&lt;/p&gt;&lt;ol&gt;  &lt;li&gt;Go to Tools--&amp;gt;Options, Expand Environment and Select Keyboard. &lt;/li&gt;  &lt;li&gt;In the 'Show Commands containing' textbox type 'TextEditorFont' &lt;/li&gt;  &lt;li&gt;In the Press shortcut keys textbox type Ctrl+Shift+Alt+DownArrow, Select the DecreaseTextEditorFontSize Macro above and click Assign. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a href="http://lh6.ggpht.com/_97nQwcNfnvg/Spc32pYoxwI/AAAAAAAAAUE/RU3fr3xxDug/s1600-h/Picture%20%28Device%20Independent%20Bitmap%29%202%5B8%5D.jpg"&gt;&lt;img style="border-width: 0px; display: inline;" title="Keyboard Options Dialog" alt="Keyboard Options Dialog" src="http://lh6.ggpht.com/_97nQwcNfnvg/Spc33MwOrLI/AAAAAAAAAUI/aeQ0z02lDMI/Picture%20%28Device%20Independent%20Bitmap%29%202_thumb%5B4%5D.jpg?imgmax=800" border="0" height="385" width="648" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Repeat for Ctrl+Shift+Alt+UpArrow and IncreaseTextEditorFontSize.&lt;/p&gt;&lt;p&gt;Now in the future when you need to quickly change the size of your font in the text editor, you can either double click the macro or use your newly created shortcut keys&lt;/p&gt;&lt;p&gt;Note: if you really do present from your main development machine, I would recommend that you create a macro that can quickly change all your standard environment (fonts/colors/size/etc…) settings at one time.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-5160611193952922169?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/5MKG2s27zbo" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/5MKG2s27zbo/intro-to-visual-studio-macros-and-most.html</link><author>noreply@blogger.com (Brian Schmitt)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh3.ggpht.com/_97nQwcNfnvg/Spc32XnSGOI/AAAAAAAAAUA/_fJgtrjbsFU/s72-c/Picture%20%28Device%20Independent%20Bitmap%29%201_thumb%5B1%5D.jpg?imgmax=800" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://www.brianschmitt.com/2009/08/intro-to-visual-studio-macros-and-most.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-3174602118926954924.post-679560254153999210</guid><pubDate>Wed, 26 Aug 2009 02:07:00 +0000</pubDate><atom:updated>2009-09-01T23:03:59.626-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">Macros</category><category domain="http://www.blogger.com/atom/ns#">Help</category><title>Better Visual Studio F1</title><description>&lt;p&gt;So recently there have been some great tips on turning off the F1 key in Visual Studio.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/2009/08/13/six-things-that-will-happen-when-you-uninstall-your-msdn-documentation.aspx"&gt;Roy Osherove&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/infinitiesloop/archive/2008/07/18/visual-studio-tip-disable-f1.aspx"&gt;Infinities Loop&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;While that is useful in turning off the Visual Studio help, it may not be useful in the event that you actually NEED help.&lt;/p&gt;  &lt;p&gt;I have found it useful to re-bind F1 to a macro that will take the currently highlighted word from your Visual Studio text editor and perform a search at the designated site.&lt;/p&gt;  &lt;p&gt;I have provided code below to allow you to quickly search &lt;a href="http://www.stackoverflow.com/"&gt;StackOverflow&lt;/a&gt;, Google, MSDN, and &lt;a href="http://www.searchdotnet.com/"&gt;Searchdotnet&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Caveats - The below script will only work in the text editor, I can provide additional code that will also use the selected text from the output window or the html-editor.  (I tried to keep it simple.)&lt;/p&gt;  &lt;p&gt;I love macros in VS and think they are highly under used, I will be posting more soon, so subscribe and welcome to my new blog!&lt;/p&gt;  &lt;p&gt;Take your pick of the four provided below (or bind several to the key combinations F1, Alt+F1, Ctrl+F1, etc...)&lt;/p&gt;  &lt;pre class="brush: vb;"&gt;Imports EnvDTE&lt;br /&gt;Imports System.Web&lt;br /&gt;&lt;br /&gt;Public Module Search&lt;br /&gt;&lt;br /&gt;#Region "Search Internet Sites"&lt;br /&gt;  Public Const GOOGLE_FORMAT As String = "www.google.com/search?q={0}"&lt;br /&gt;  Public Const STACKOVERFLOW_FORMAT As String = "http://www.stackoverflow.com/search?q={0}"&lt;br /&gt;  Public Const SEARCHDOTNET_FORMAT As String = "http://searchdotnet.com/results.aspx?cx=002213837942349435108:jki1okx03jq&amp;amp;q={0}&amp;amp;sa=Search&amp;amp;cof=FORID:9#1144"&lt;br /&gt;  Public Const MSDN_FORMAT As String = "http://social.msdn.microsoft.com/Search/en-US/?query={0}&amp;amp;ac=8"&lt;br /&gt;   &lt;br /&gt;  Public Sub SearchStackOverflowForSelectedText()&lt;br /&gt;      SearchWebPage(STACKOVERFLOW_FORMAT)&lt;br /&gt;  End Sub&lt;br /&gt;  Public Sub SearchGoogleForSelectedText()&lt;br /&gt;      SearchWebPage(GOOGLE_FORMAT)&lt;br /&gt;  End Sub&lt;br /&gt;  Public Sub SearchSearchDotNetForSelectedText()&lt;br /&gt;      SearchWebPage(SEARCHDOTNET_FORMAT)&lt;br /&gt;  End Sub&lt;br /&gt;      Public Sub SearchMSDNForSelectedText()&lt;br /&gt;      SearchWebPage(MSDN_FORMAT)&lt;br /&gt;  End Sub&lt;br /&gt;  Private Sub SearchWebPage(ByVal SearchURLFormat As String)&lt;br /&gt;      Dim sel As EnvDTE.TextSelection = DTE.ActiveWindow.Selection&lt;br /&gt;      Dim srchTxt As String = sel.Text.Trim&lt;br /&gt;      If srchTxt.Length &amp;gt; 0 Then&lt;br /&gt;          DTE.ItemOperations.Navigate(String.Format(SearchURLFormat, HttpUtility.UrlEncode(srchTxt)))&lt;br /&gt;      End If&lt;br /&gt;  End Sub&lt;br /&gt;#End Region&lt;br /&gt;&lt;br /&gt;End Module&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3174602118926954924-679560254153999210?l=www.brianschmitt.com' alt='' /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/IObservable/~4/XOlfeev_Ry8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/IObservable/~3/XOlfeev_Ry8/better-visual-studio-f1.html</link><author>noreply@blogger.com (Brian Schmitt)</author><thr:total>2</thr:total><feedburner:origLink>http://www.brianschmitt.com/2009/08/better-visual-studio-f1.html</feedburner:origLink></item></channel></rss>

