How to change the title bar text of Visual Studio

2019-01-16 06:04发布

We work on several different branches of the same code, and when working on two branches at once, it can become confusing and time wasting.

Presently, the VS title bar has the text <solution-name> - Visual Studio.

Is it possible for me to write an extension that will make that text <solution-name>: <branch-name> - <Visual Studio>?

11条回答
The star\"
2楼-- · 2019-01-16 06:31

I added a symbolic link with a different name targeting the solution file. Open the solution with the symbolic link and the window title has the symbolic link name.

In windows: mklink BlawBranch.sln Blaw.sln

EDIT: Found that a hard link breaks if target .sln file is updated by our source control. A symbolic link doesn't have the same problem.

查看更多
混吃等死
3楼-- · 2019-01-16 06:38

there is a property by name AppName for any visual studio based IDE, that should do the trick.

查看更多
淡お忘
4楼-- · 2019-01-16 06:38

From http://www.helixoft.com/blog/archives/32 sets the title to the current filename. It also works on Visual Studio 10

  Private timer As System.Threading.Timer
Private ideTitle As String = Nothing
Declare Auto Function SetWindowText Lib "user32" (ByVal hWnd As System.IntPtr, _
ByVal lpstring As String) As Boolean

'''<summary>Called when any window in VS gets activated.</summary>
'''<param name="GotFocus">Window that got focus.</param>
'''<param name="LostFocus">Window that lost focus.</param>
Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
    Try
        If timer Is Nothing Then
            ' Create timer which refreshes the caption because
            ' IDE resets the caption very often
            Dim autoEvent As New System.Threading.AutoResetEvent(False)
            Dim timerDelegate As System.Threading.TimerCallback = _
                AddressOf tick
            timer = New System.Threading.Timer(timerDelegate, autoEvent, 0, 200)
        End If

        If GotFocus.Document Is Nothing Then
            ideTitle = Nothing
        Else
            ideTitle = GotFocus.Document.FullName
            showTitle(ideTitle)
        End If
    Catch ex As System.Exception
    End Try
End Sub

''' <summary>Dispose the timer on IDE shutdown.</summary>
Public Sub DTEEvents_OnBeginShutdown() Handles DTEEvents.OnBeginShutdown
    If Not timer Is Nothing Then
        timer.Dispose()
    End If
End Sub

'''<summary>Called by timer.</summary>
Public Sub tick(ByVal state As Object)
    Try
        If Not ideTitle Is Nothing Then
            showTitle(ideTitle)
        End If
    Catch ex As System.Exception
    End Try
End Sub

'''<summary>Shows the title in main window.</summary>
Private Sub showTitle(ByVal title As String)
    SetWindowText(New System.IntPtr(DTE.MainWindow.HWnd), title & " - " & DTE.Name)
End Sub
查看更多
家丑人穷心不美
5楼-- · 2019-01-16 06:38

In 2012, you have to set System.Windows.Application.Current.MainWindow.Title in order for this to work. This will update both the TaskBarItem title and the MainWindow title.

This is only possible from the main thread and since the title will get updated at various points by Visual Studio, you have to hook up to some events and reset it to whatever you wanted it to be (in my AddIn, I use some EnvDTE.SolutionEvents among others).

Hope this helps.

查看更多
Evening l夕情丶
6楼-- · 2019-01-16 06:40

Perhaps a simpler solution would be to use virtual desktops? Spacial arrangement is easier to remember, you could group any related windows with the corresponding VS, and switching would be simpler.

查看更多
登录 后发表回答