locked
Click on submenu item to open windows form RRS feed

  • Question

  • I am currently trying to develop an extension tool for Visual Studio 2013 in C#, and i have created the top level menu.

    My question is upon clicking on the "Create Rules", how can i open up Form1.cs which i have added in my package? Is anyone able to point me to the right direction as i am totally new to this and is stucked.

    Any help will be very much appreciated and thank you in advance

    Wednesday, March 4, 2015 9:25 AM

Answers

All replies

  • I found this link, and it proves to be helpful. https://msdn.microsoft.com/en-us/library/bb165468.aspx , it requires the editing of the .cs file of the package. To make the form show, simple do:

    Form1 formTest = new Form1();

    formTest.Show();

    • Marked as answer by Tan Stanley Wednesday, March 4, 2015 10:15 AM
    Wednesday, March 4, 2015 10:15 AM
  • After you get the form showing if you run into the issue of making it modal and center parent like I did you can you code like this:

           #region Show Modal Window
            internal void ShowModalWindow(System.Windows.Window win)
            {
                IntPtr hwnd;

                this._uiShell.GetDialogOwnerHwnd(out hwnd);
                win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
                this._uiShell.EnableModeless(0);
                try
                {
                    WindowHelper.ShowModal(win, hwnd);
                }
                finally
                {
                    //this will take place after the window is closed
                    this._uiShell.EnableModeless(1);
                }
            }
            #endregion

    This method is part of a larger class that already has _uiShell, it was set by using this code within the package Initialize method:

    IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

    But the basic use is create your wpf form than pass it to this method, it will be shown as modal and center parent.


    Wednesday, March 4, 2015 5:17 PM