如何更改Visual Studio的标题栏文本

我们在同一个代码的几个不同的分支上工作,当一次在两个分支上工作时,会变得混乱和浪费时间。

目前,VS标题栏有文本<solution-name> - Visual Studio

是否可以写一个扩展名,使该文本<solution-name>: <branch-name> - <Visual Studio>

我刚刚创build了一个小的Visual Studio扩展,可以帮助: http : //visualstudiogallery.msdn.microsoft.com/f3f23845-5b1e-4811-882f-60b7181fa6d6

每当Visual Studio的两个实例运行时,这个小扩展都会检测到,并将Visual Studio的窗口标题更改为包含解决scheme的父文件夹名称。 它将因此将SolutionFolder – Microsoft Visual Studio更改为SolutionFolderParent \ SolutionFolder – Microsoft Visual Studio

这在分支解决scheme时特别有用:可以很容易地识别您正在使用哪个分支,在两者都具有相同的解决scheme名称的情况下。

官方网页: http : //erwinmayer.com/labs/visual-studio-2010-extension-rename-visual-studio-window-title/

查看VSCommands 2010 Lite的最新版本。 它引入了一个名为Friendly Solution Name的特性,您可以设置一个正则expression式来从文件夹结构中提取分支名称,并将其放置在Visual Studio主窗口标题中。 更多细节: http : //vscommands.com/releasenotes/3.6.8.0和http://vscommands.com/releasenotes/3.6.9.0

MSDN下载页面

尝试设置MainWindow.Caption会引发exception。 您必须使用Win32的SetWindowText函数来更改标题,但要注意:Visual Studio会重置标题栏文本,因此您应该实现一个定时器来设置所需的文本。 下面的加载项的Connect类的代码将永久(或者,只要加载项正在运行)将标题栏文本保持为“Hello World!”。

 public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; resetTitleTimer = new Timer(new TimerCallback(SetMainWindowTitle), "Hello world!", 0, 10); } [DllImport("user32.dll")] private static extern bool SetWindowText(IntPtr hWnd, string lpString); private void SetMainWindowTitle(object state) { IntPtr hWnd = (IntPtr)_applicationObject.MainWindow.HWnd; SetWindowText(hWnd, "Hello World!"); } 

我添加了一个不同名称的解决scheme文件的符号链接。 用符号链接打开解决scheme,窗口标题具有符号链接名称。

在Windows中:mklink BlawBranch.sln Blaw.sln

编辑:发现如果目标.sln文件由我们的源代码pipe理更新,硬链接会中断。 符号链接不具有相同的问题。

通过将其定义为expression式来更改Visual Studio标题栏的另一个扩展: http : //visualstudiogallery.msdn.microsoft.com/2e8ebfe4-023f-4c4d-9b7a-d05bbc5cb239

使用“标题expression式”的设置使得这个插件相当灵活。

说实话,我不确定我是否正确理解你的问题,但是我在这里问过一个似乎是类似问题的人:

使用相同的Visual Studio 2005解决scheme的不同版本/分支

也许更简单的解决scheme是使用虚拟桌面? 空间布局更容易记住,你可以将任何相关的窗口与相应的VS分组,并且切换会更简单。

对于任何基于视觉工作室的IDE,都有一个名为AppName的属性,应该这样做。

http://www.helixoft.com/blog/archives/32将标题设置为当前文件名。; 它也适用于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 

在2012年,你必须设置System.Windows.Application.Current.MainWindow.Title为了这个工作。 这将更新TaskBarItem标题和MainWindow标题。

这是唯一可能的主线程,因为标题将在Visual Studio的各个点更新,你必须连接到一些事件,并将其重置为任何你想要的(在我的AddIn中,我使用了一些EnvDTE.SolutionEvents等)。

希望这可以帮助。

在VS自动化模型中有

 _DTE.MainWindow.Capation 

你可以开始。

请参阅http://msdn.microsoft.com/zh-CN/library/envdte._dte.mainwindow.aspx