共用方式為


How to: Open an Options Page Programmatically

You can display an options page programmatically so that users of your package can configure it during setup. To change settings after the package is installed, a user can still access the options page by using the Options dialog box.

To display a custom options page

  1. Create an options page. For more information, see Creating Options Pages By Using Managed Package Framework Classes.

  2. Get the Type of the options page by applying the typeof keyword to the name of the class that defines the options page.

  3. Call the ShowOptionPage method by using the Type of the options page as a parameter.

    The following example displays an options page named HelloWorldOptions.

    Dim optionsPageType As Type = GetType(HelloWorldOptions)
    
    Type optionsPageType = typeof(HelloWorldOptions);
    ShowOptionPage(optionsPageType);
    

To display an options page that is defined by Visual Studio

  1. In the registry subkey HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\ToolsOptionsPages\, find the node for the options page that you want to display and then copy its GUID, which is the value of the Page key.

  2. Create a CommandID instance that has the constants GUID_VSStandardCommandSet97 and ToolsOptions as parameters.

    This specifies the Options dialog box.

  3. Call the GlobalInvoke method by using the CommandID instance and the GUID string as parameters.

    The following example displays the General tab of the Text Editor options page.

    ' GUID of Options>TextEditor>General 
    Dim targetGUID As String = "734A5DE2-DEBA-11d0-A6D0-00C04FB67F6A"
    Dim command = New CommandID(VSConstants.GUID_VSStandardCommandSet97, VSConstants.cmdidToolsOptions)
    Dim mcs = TryCast(GetService(GetType(IMenuCommandService)), MenuCommandService)
    
    // GUID of Options>TextEditor>General
    string targetGUID = "734A5DE2-DEBA-11d0-A6D0-00C04FB67F6A";
    var command = new CommandID(
        VSConstants.GUID_VSStandardCommandSet97, 
        VSConstants.cmdidToolsOptions);
    var mcs = GetService(typeof(IMenuCommandService)) 
        as MenuCommandService;
    mcs.GlobalInvoke(command, targetGUID);
    

See Also

Reference

Package

Concepts

Creating Options Pages By Using Automation

Other Resources

Options Pages