2008年,一個稍微好一點的方式來寫從上面的接受的答案宏是使用該解決方案的事件,而不是文件的 - 這可以讓你隨時編輯標題欄,即使你沒有選擇文件。下面是我的同事和我基於另一個的宏 - 您將需要更改第15-18行,以便從源目錄中獲取您的分支名稱,以便設置。
01 Private timer As System.Threading.Timer
02 Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, ByVal lpstring As String) As Boolean
03
04 Private _branchName As String = String.Empty
05 Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
06 Try
07 If timer Is Nothing Then
08 ' Create timer which refreshes the caption because
09 ' IDE resets the caption very often
10 Dim autoEvent As New System.Threading.AutoResetEvent(False)
11 Dim timerDelegate As System.Threading.TimerCallback = _
12 AddressOf tick
13 timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 25)
14 End If
15 Dim sourceIndex As Integer = DTE.Solution.FullName.IndexOf("\Source")
16 Dim shortTitle As String = DTE.Solution.FullName.Substring(0, sourceIndex)
17 Dim lastIndex As Integer = shortTitle.LastIndexOf("\")
18 _branchName = shortTitle.Substring(lastIndex + 1)
19 showTitle(_branchName)
20 Catch ex As Exception
21
22 End Try
23 End Sub
24
25 Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
26 If Not timer Is Nothing Then
27 timer.Dispose()
28 End If
29 End Sub
30
31
32 ''' <summary>Dispose the timer on IDE shutdown.</summary>
33 Public Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown
34 If Not timer Is Nothing Then
35 timer.Dispose()
36 End If
37 End Sub
38
39 '''<summary>Called by timer.</summary>
40 Public Sub tick(ByVal state As Object)
41 Try
42 showTitle(_branchName)
43 Catch ex As System.Exception
44 End Try
45 End Sub
46
47 '''<summary>Shows the title in main window.</summary>
48 Private Sub showTitle(ByVal title As String)
49 SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
50 End Sub
[文件路徑頁腳](https://visualstudiogallery.msdn.microsoft.com/d9fc97d4-3b42-4b56-ba47-23f8b81ebd17/)也是一個不錯的擴展 – dan 2016-07-31 07:40:30