问题描述
请为我提供一个非常简单的VS Package C#项目,用于自定义Visual Studio的状态栏。我只是想在状态栏中显示一条消息,没有别的。因为我是初学者,所以互联网和msdn的样本都不起作用,也不复杂。在此先感谢。
当我尝试下面的代码时,它在GetService中显示错误为在相关上下文中不存在。
Please provide me a very simple VS Package C# project for customizing Visual Studio's status bar. I just want to display a message in the status bar, nothing else. The samples which are in internet and also msdn are not working and little complex since I'm a beginner. Thanks in advance.
While I'm trying the below code, it shows error in GetService as "doesn't exists in the corrent context".
IVsStatusbar statusBar = (IVsStatusbar)GetService(typeof(SVsStatusbar));
int frozen;
statusBar.IsFrozen(out frozen);
if (frozen == 0)
{
statusBar.SetText("Here's some static text.");
}
通过使用语句IVsStatusbar statusbar =(IVsStatusbar)GetService(typeof(SVsStatusbar)),我可以实现包类中的要求。但是,如果我在另一个不是包类的类中使用相同的,它就不起作用了。无法使用GetService方法。它显示为GetService在当前上下文中不存在。如何从另一个类获取服务,或者我可以从Package类获取服务并将其传递给另一个类?我正在使用VS2010进行编码。
By using the statement IVsStatusbar statusbar=(IVsStatusbar)GetService(typeof(SVsStatusbar)), I can achieve the requirement in package class. But if I'm using the same in another class which is not a package class, its not working. Unable to use GetService method. Its showing as "GetService doesn't exists in the current context". How can I get the service from an another class or can I get the service from the Package class and pass it to an another class? I'm using VS2010 to code.
推荐答案
这篇关于需要一个示例来自定义Visual Studio状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!