如何更改Visual Studio的标题栏文本 [英] How to change the title bar text of Visual Studio
问题描述
我们在同一代码的多个不同分支上工作,当同时在两个分支上工作时,可能会造成混乱和浪费时间.
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.
当前,VS标题栏的文字为<solution-name> - Visual Studio
.
Presently, the VS title bar has the text <solution-name> - Visual Studio
.
我是否可以编写一个扩展名,使该文本成为<solution-name>: <branch-name> - <Visual Studio>
?
Is it possible for me to write an extension that will make that text <solution-name>: <branch-name> - <Visual Studio>
?
推荐答案
尝试设置MainWindow.Caption会引发异常.您必须使用Win32 SetWindowText函数来更改标题,但要注意:Visual Studio会在放下帽子时重置标题栏文本,因此您应该实现一个Timer来继续设置所需的文本.外接程序Connect
类中的以下代码将永久(或只要外接程序正在运行)将标题栏文本保持为"Hello World!".
Trying to set MainWindow.Caption throws an exception. You have to use the Win32 SetWindowText function to change the title, but beware: Visual Studio resets the title bar text at the drop of a hat, so you should implement a Timer to keep setting your desired text. The following code from the Connect
class of the add-in will permanently (or, as long as the add-in is running) keep the title bar text as "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!");
}
这篇关于如何更改Visual Studio的标题栏文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!