如何更改 Visual Studio 的标题栏文本 [英] How to change the title bar text of Visual Studio

查看:31
本文介绍了如何更改 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 标题栏有文字 - Visual Studio.

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

我是否可以编写一个扩展程序,使该文本 : - <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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆