[英]How to make a dialog appear when Visual Studio is started. - VS Extension
I am building a Visual Studio extension and I am stumped on how I would show a dialog when visual studio is started. 我正在构建一个Visual Studio扩展,我对如何在Visual Studio启动时显示对话框感到难过。
The main use for it is going to be when Visual studio starts my extension will check for updates if an update is found a dialog appears. 它的主要用途是当Visual Studio启动时,我的扩展将检查更新,如果发现更新,则会出现一个对话框。
Information on extensions is very scarce so I have no idea how to do this. 有关扩展的信息非常稀缺,所以我不知道如何做到这一点。 I am using C#.
我正在使用C#。
Edit: I have tried adding the code in the package file that has all of the command code/callbacks into it's initialize event and it shows the dialog before visual studio appears to have even loaded and does not continue to load until I close it. 编辑:我已经尝试将包含所有命令代码/回调的包文件中的代码添加到它的初始化事件中,它在visual studio看起来甚至已加载之前显示对话框,并且在我关闭之前不会继续加载。 I feel like I am getting closer though.
我觉得我越来越近了。
Is their an extension start up command I can create in VSCT file, kind of like they have for menu items? 他们是一个扩展启动命令,我可以在VSCT文件中创建,有点像菜单项吗?
I was able to figure out my problem. 我弄清楚了我的问题。 It took alot of trial and error due to the lack of info.
由于缺乏信息,它经历了大量的试验和错误。 I had originally tried the OnStartupcomplete() event but it was not working for me, hence I came here.
我最初尝试过OnStartupcomplete()事件,但它不适用于我,因此我来到这里。 The reason why it was not working was because the DTE object wasn't initialized at that point.
它不起作用的原因是因为DTE对象在那时没有被初始化。 So I was able to create the object and add the handler.
所以我能够创建对象并添加处理程序。
[ProvideAutoLoad(Microsoft.VisualStudio.Shell.Interop.UIContextGuids.NoSolution)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string)]
protected override void Initialize()
{
//DTE gets called
var dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
_EventsObj = dte.Events.DTEEvents;
_EventsObj.OnStartupComplete += OnStartupComplete;
}
public void OnStartupComplete()
{
//This is the code to launch the dialog.
EvaluationDialog EvalForm = new EvaluationDialog();
EvalForm.ShowDialog();
}
I'm assuming you are using a Visual Studio Add-in project. 我假设您正在使用Visual Studio加载项项目。 If you want just a message box, in the Connect.cs file, add a reference to
System.Windows.Forms
and a using
statement: 如果只需要一个消息框,请在Connect.cs文件中添加对
System.Windows.Forms
的引用和using
语句:
using System.Windows.Forms;
In the OnConnection
method: 在
OnConnection
方法中:
public void OnConnection(object application,
ext_ConnectMode connectMode,
object addInInst, ref Array custom)
{
MessageBox.Show("message box");
// or you could use your on dialog class
var myDialog=new MyDialog();
myDialog.Show();
// ...
}
We are using OnAfterOpenProject. 我们正在使用OnAfterOpenProject。 You can check for updates and bring up a dialog if found.
您可以检查更新并在找到时打开对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.