Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

Information on extensions is very scarce so I have no idea how to do this. I am using 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. 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?

like image 519
user1632018 Avatar asked Feb 28 '13 20:02

user1632018


People also ask

Where is the dialog box in Visual Studio?

The values for individual controls and the dialog box appear in the lower right of the Visual Studio status bar when you select them.

How to create modal dialog in c#?

To create a modal dialog box, call either of the two public constructors declared in CDialog. Next, call the dialog object's DoModal member function to display the dialog box and manage interaction with it until the user chooses OK or Cancel. This management by DoModal is what makes the dialog box modal.

How to see the Options in Visual Studio?

You can access Options from the Tools menu.

How do I create a custom extension in Visual Studio?

Use the Manage Extensions dialog box to install and manage Visual Studio extensions. To open the Manage Extensions dialog, choose Extensions > Manage Extensions. Or, type Extensions in the search box and choose Manage Extensions.


2 Answers

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. The reason why it was not working was because the DTE object wasn't initialized at that point. 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();

    }
like image 169
user1632018 Avatar answered Nov 15 '22 05:11

user1632018


I'm assuming you are using a Visual Studio Add-in project. If you want just a message box, in the Connect.cs file, add a reference to System.Windows.Forms and a using statement:

using System.Windows.Forms;

In the OnConnection method:

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();

    // ...
}
like image 38
Alex Filipovici Avatar answered Nov 15 '22 05:11

Alex Filipovici